Skip to content

Commit c0813e4

Browse files
committed
Address catalogue conformance findings
1 parent 6dd6a4c commit c0813e4

11 files changed

Lines changed: 88 additions & 36 deletions

File tree

go/rpc/catalogue_conformance_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,20 @@ func TestCatalogSearchResultPreservesRefusalsAndFailures(t *testing.T) {
136136
})
137137
}
138138
}
139+
140+
func TestCatalogSearchResultRejectsUnknownCandidateKinds(t *testing.T) {
141+
_, err := unmarshalCatalogSearchResult([]byte(`{
142+
"kind":"succeeded",
143+
"searchId":"search-unknown",
144+
"candidates":[{
145+
"kind":"future-kind",
146+
"handle":"opaque:future/03-do-not-parse",
147+
"rawCard":{"secret":"must-not-survive"}
148+
}],
149+
"truncated":false,
150+
"negotiated":{"runtimeProtocolVersion":1,"grantedCapabilities":[]}
151+
}`))
152+
if err == nil {
153+
t.Fatal("unknown catalogue candidate kind with rawCard must be rejected")
154+
}
155+
}

go/rpc/zrpc.go

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/rpc/zrpc_encoding.go

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/scripts/codegen/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/scripts/codegen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"generate:java": "tsx java.ts"
88
},
99
"dependencies": {
10-
"@github/copilot": "^1.0.83-3",
10+
"@github/copilot": "1.0.83-3",
1111
"json-schema": "^0.4.0",
1212
"tsx": "^4.23.13"
1313
}

java/sdk/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ did not produce the multi-release output. Re-build on JDK 25+ and verify the
805805
<workingDirectory>${project.parent.basedir}/scripts/codegen</workingDirectory>
806806
<arguments>
807807
<argument>install</argument>
808+
<argument>--save-exact</argument>
808809
<argument>@github/copilot@${copilot.schema.version}</argument>
809810
</arguments>
810811
</configuration>

python/copilot/generated/rpc.py

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/test_rpc_generated.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,38 @@ async def test_catalog_search_preserves_refusals_and_failures(payload, expected_
261261
)
262262

263263
assert isinstance(result, expected_type)
264+
265+
266+
@pytest.mark.asyncio
267+
async def test_catalog_search_rejects_unknown_candidate_kinds():
268+
client = AsyncMock()
269+
client.request = AsyncMock(
270+
return_value={
271+
"kind": "succeeded",
272+
"searchId": "search-unknown",
273+
"candidates": [
274+
{
275+
"kind": "future-kind",
276+
"handle": "opaque:future/03-do-not-parse",
277+
"rawCard": {"secret": "must-not-survive"},
278+
}
279+
],
280+
"truncated": False,
281+
"negotiated": {
282+
"runtimeProtocolVersion": 1,
283+
"grantedCapabilities": [],
284+
},
285+
}
286+
)
287+
api = ServerCatalogApi(client)
288+
289+
with pytest.raises(ValueError, match="Unknown CatalogCandidate kind"):
290+
await api.search(
291+
CatalogSearchRequest(
292+
contract=CatalogClientContract(
293+
protocol_version=1,
294+
required_capabilities=[],
295+
),
296+
query="example",
297+
)
298+
)

scripts/codegen/catalogue-conformance.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const sdkPackageLock = JSON.parse(
2020
) as { packages?: Record<string, { version?: string }> };
2121
const expectedPackageVersion =
2222
sdkPackageLock.packages?.["node_modules/@github/copilot"]?.version;
23+
const javaCodegenPackageJson = JSON.parse(
24+
await fs.readFile(path.join(REPO_ROOT, "java/scripts/codegen/package.json"), "utf8")
25+
) as { dependencies?: Record<string, string> };
26+
const javaCodegenPackageVersion =
27+
javaCodegenPackageJson.dependencies?.["@github/copilot"];
2328
const packageJson = JSON.parse(
2429
await fs.readFile(path.join(packageRoot, "package.json"), "utf8")
2530
) as { version?: string };
@@ -51,6 +56,10 @@ assert(
5156
packageJson.version === expectedPackageVersion,
5257
`expected @github/copilot ${expectedPackageVersion}, received ${packageJson.version ?? "unknown"}`
5358
);
59+
assert(
60+
javaCodegenPackageVersion === expectedPackageVersion,
61+
`java/scripts/codegen must pin @github/copilot exactly to ${expectedPackageVersion}`
62+
);
5463
assert(
5564
schema.server?.catalog?.search?.rpcMethod === "catalog.search",
5665
"catalog.search is missing"

scripts/codegen/go.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ function emitGoFlatDiscriminatedUnion(
18041804

18051805
const unmarshalFuncName = goUnexportedFunctionName("unmarshal", typeName);
18061806
const rawDataName = `Raw${typeName}${ctx.discriminatedUnionRawVariantSuffix ?? "Data"}`;
1807-
const hasRawVariant = discriminator.valueKind === "string";
1807+
const hasRawVariant = discriminator.valueKind === "string" && typeName !== "CatalogCandidate";
18081808
const markerName = toGoUnexportedIdentifier(typeName);
18091809
ctx.discriminatedUnions.set(typeName, { typeName, unmarshalFuncName });
18101810

@@ -1893,7 +1893,7 @@ function emitGoFlatDiscriminatedUnion(
18931893
unmarshalLines.push(`\t\treturn &${rawDataName}{Discriminator: ${rawDiscExpr}, Raw: data}, nil`);
18941894
}
18951895
unmarshalLines.push(`\t}`);
1896-
if (discriminator.valueKind === "boolean") {
1896+
if (!hasRawVariant) {
18971897
unmarshalLines.push(`\treturn nil, errors.New("data did not match any union variant for ${typeName}")`);
18981898
}
18991899
unmarshalLines.push(`}`);

0 commit comments

Comments
 (0)