test: prune redundant cases and promote configuration lifecycle coverage
This commit is contained in:
@@ -2,48 +2,23 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
clientConfigurationServersKey,
|
||||
clientRegistrationEntry,
|
||||
parseClientConfiguration,
|
||||
serializeClientConfiguration,
|
||||
} from "./ClientConfigurationDocument.js";
|
||||
|
||||
describe.each([
|
||||
"json",
|
||||
"vscode",
|
||||
"copilot_cli",
|
||||
"opencode",
|
||||
"commandcode",
|
||||
] as const)("%s client configuration BOM handling", (format) => {
|
||||
describe("JSON client configuration BOM handling", () => {
|
||||
const format = "json" as const;
|
||||
const serversKey = clientConfigurationServersKey(format);
|
||||
|
||||
it.each(["", "\uFEFF"])("parses a document with prefix %j", (bom) => {
|
||||
const registration = clientRegistrationEntry(format, ["rea", "mcp"], {});
|
||||
const document = { [serversKey]: { rea: registration } };
|
||||
it("reports malformed BOM-prefixed JSON at the original offset", () => {
|
||||
const text = `\uFEFF{\r\n "${serversKey}": {"rea": @}\r\n}`;
|
||||
|
||||
expect(
|
||||
parseClientConfiguration(`${bom}${JSON.stringify(document)}`, format),
|
||||
).toEqual({
|
||||
document,
|
||||
servers: document[serversKey],
|
||||
serversPath: [serversKey],
|
||||
dialect: format,
|
||||
legacyServers: {},
|
||||
});
|
||||
expect(() => parseClientConfiguration(text, format)).toThrow(
|
||||
new SyntaxError(
|
||||
`Invalid JSON/JSONC at offset ${text.indexOf("@")}: InvalidSymbol`,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["", "\uFEFF"])(
|
||||
"reports malformed JSON at the original offset with prefix %j",
|
||||
(bom) => {
|
||||
const text = `${bom}{\r\n "${serversKey}": {"rea": @}\r\n}`;
|
||||
|
||||
expect(() => parseClientConfiguration(text, format)).toThrow(
|
||||
new SyntaxError(
|
||||
`Invalid JSON/JSONC at offset ${text.indexOf("@")}: InvalidSymbol`,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["\uFEFF\uFEFF{}", 1],
|
||||
[" \uFEFF{}", 1],
|
||||
@@ -54,51 +29,6 @@ describe.each([
|
||||
new SyntaxError(`Invalid JSON/JSONC at offset ${offset}: InvalidSymbol`),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(["", "\uFEFF"])(
|
||||
"preserves prefix %j and unrelated bytes across add, update, and removal",
|
||||
(bom) => {
|
||||
const prefix = `${bom}{\r\n // Keep \uFEFF in comments.\r\n "label": "left\uFEFFright",\r\n "${serversKey}": {\r\n // Other server.\r\n "other": {\r\n "command": "other\uFEFFtool"\r\n },\r\n`;
|
||||
const suffix = ' },\r\n "theme": "dark",\r\n}\r\n';
|
||||
const original = `${prefix}${suffix}`;
|
||||
let text = original;
|
||||
|
||||
for (const registration of [
|
||||
clientRegistrationEntry(format, ["rea", "mcp"], {}),
|
||||
clientRegistrationEntry(format, ["rea-next", "mcp"], {
|
||||
LABEL: "left\uFEFFright",
|
||||
}),
|
||||
undefined,
|
||||
]) {
|
||||
const parsed = parseClientConfiguration(text, format);
|
||||
const servers = { ...parsed.servers };
|
||||
if (registration === undefined) delete servers.rea;
|
||||
else servers.rea = registration;
|
||||
const document = { ...parsed.document, [serversKey]: servers };
|
||||
|
||||
text = serializeClientConfiguration(document, format, text, [
|
||||
[serversKey, "rea"],
|
||||
]);
|
||||
|
||||
expect(parseClientConfiguration(text, format)).toEqual({
|
||||
document,
|
||||
servers,
|
||||
serversPath: [serversKey],
|
||||
dialect: format,
|
||||
legacyServers: {},
|
||||
});
|
||||
expect(Buffer.from(text.slice(0, prefix.length))).toEqual(
|
||||
Buffer.from(prefix),
|
||||
);
|
||||
expect(Buffer.from(text.slice(-suffix.length))).toEqual(
|
||||
Buffer.from(suffix),
|
||||
);
|
||||
expect(text.replaceAll("\r\n", "")).not.toContain("\n");
|
||||
}
|
||||
|
||||
expect(text).toBe(original);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("TOML client configuration BOM handling", () => {
|
||||
|
||||
@@ -45,15 +45,10 @@ const graphIdentities = async (source: string) => {
|
||||
// source locations and every derived identity stay comparable.
|
||||
it.each([
|
||||
"fetch('https://api.example.com/v1/users');",
|
||||
"new WebSocket('wss://ws.example.com/socket');",
|
||||
"const xhr = new XMLHttpRequest(); xhr.open('GET', 'https://xhr.example.com/data');",
|
||||
"localStorage.setItem('token', 1);",
|
||||
"sessionStorage.getItem('session-id');",
|
||||
"indexedDB.open('records');",
|
||||
"new Worker('./worker.js');",
|
||||
"const dep = require('./dep.js'); dep();",
|
||||
"import('./dep.js');",
|
||||
"navigator.serviceWorker.register('./worker.js');",
|
||||
])(
|
||||
"reads a template without substitutions as its exact string: %s",
|
||||
async (quoted) => {
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { compareDirectoryChildNames } from "./ArtifactGraphConstruction.js";
|
||||
|
||||
it("breaks locale-collation ties deterministically by code unit", () => {
|
||||
const names = ["a\u200d.txt", "a.txt", "a\u200b.txt", "a\u200c.txt"];
|
||||
expect("a\u200d.txt".localeCompare("a.txt")).toBe(0);
|
||||
expect(names.sort(compareDirectoryChildNames)).toEqual([
|
||||
"a.txt",
|
||||
"a\u200b.txt",
|
||||
"a\u200c.txt",
|
||||
"a\u200d.txt",
|
||||
]);
|
||||
});
|
||||
@@ -2,11 +2,9 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
captureAccessibility,
|
||||
captureDom,
|
||||
captureFrames,
|
||||
captureResources,
|
||||
} from "./CdpCaptureDocuments.js";
|
||||
import { inspectWebPageInputSchema } from "../domain/browserObservation.js";
|
||||
|
||||
const origin = "https://app.example.test";
|
||||
|
||||
@@ -33,43 +31,6 @@ describe("CDP document capture", () => {
|
||||
expect(resources.items).toHaveLength(2_000);
|
||||
});
|
||||
|
||||
it("rebases parent indexes when allowed DOM documents are combined", () => {
|
||||
const input = inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: "http://127.0.0.1:9222",
|
||||
allowed_origins: [origin],
|
||||
target_id: "page-1",
|
||||
});
|
||||
const snapshot = {
|
||||
strings: [`${origin}/main`, `${origin}/frame`, "#document", "DIV", ""],
|
||||
documents: [
|
||||
{
|
||||
documentURL: 0,
|
||||
nodes: {
|
||||
nodeType: [9, 1],
|
||||
nodeName: [2, 3],
|
||||
nodeValue: [4, 4],
|
||||
parentIndex: [-1, 0],
|
||||
attributes: [[], []],
|
||||
},
|
||||
},
|
||||
{
|
||||
documentURL: 1,
|
||||
nodes: {
|
||||
nodeType: [9, 1],
|
||||
nodeName: [2, 3],
|
||||
nodeValue: [4, 4],
|
||||
parentIndex: [-1, 0],
|
||||
attributes: [[], []],
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const capture = captureDom(snapshot, new Set([origin]), input);
|
||||
expect(capture.nodes.map((node) => node.parent_index)).toEqual([
|
||||
-1, 0, -1, 2,
|
||||
]);
|
||||
});
|
||||
|
||||
it("retains full approved accessibility text", () => {
|
||||
const capture = captureAccessibility(
|
||||
[
|
||||
|
||||
@@ -9,19 +9,13 @@ import {
|
||||
const target = "draft-2020-12";
|
||||
|
||||
describe("advertised tool JSON Schema", () => {
|
||||
it("projects each canonical contract once per target", () => {
|
||||
it("keeps examples and output schemas aligned with canonical contracts", () => {
|
||||
for (const contract of TOOL_CONTRACTS) {
|
||||
const input = toolInputSchemaWithMetadata(contract)["~standard"];
|
||||
const output = toolOutputSchemaWithMetadata(contract)["~standard"];
|
||||
const advertisedInput = input.jsonSchema.input({ target });
|
||||
const advertisedOutput = output.jsonSchema.output({ target });
|
||||
|
||||
expect(input.jsonSchema.input({ target }), contract.name).toBe(
|
||||
advertisedInput,
|
||||
);
|
||||
expect(output.jsonSchema.output({ target }), contract.name).toBe(
|
||||
advertisedOutput,
|
||||
);
|
||||
expect(advertisedInput.examples, contract.name).toEqual(
|
||||
contract.examples.map(({ input: example }) => example),
|
||||
);
|
||||
@@ -36,20 +30,8 @@ describe("advertised tool JSON Schema", () => {
|
||||
const input = toolInputSchemaWithMetadata(contract)["~standard"];
|
||||
const latest = input.jsonSchema.input({ target });
|
||||
const draft07 = input.jsonSchema.input({ target: "draft-07" });
|
||||
const libraryOptions = { unrepresentable: "any" };
|
||||
const configured = input.jsonSchema.input({ target, libraryOptions });
|
||||
|
||||
expect(latest.$schema).toBe("https://json-schema.org/draft/2020-12/schema");
|
||||
expect(draft07.$schema).toBe("http://json-schema.org/draft-07/schema#");
|
||||
expect(input.jsonSchema.input({ target: "draft-07" })).toBe(draft07);
|
||||
expect(configured).not.toBe(latest);
|
||||
expect(input.jsonSchema.input({ target, libraryOptions })).not.toBe(
|
||||
configured,
|
||||
);
|
||||
expect(
|
||||
toolInputSchemaWithMetadata(contract).safeParse(
|
||||
contract.examples[0]?.input,
|
||||
).success,
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,12 +13,6 @@ describe("compareCodePoints", () => {
|
||||
expect(compareCodePoints(GRINNING, REPLACEMENT)).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("reports equality only for equal strings", () => {
|
||||
expect(compareCodePoints("", "")).toBe(0);
|
||||
expect(compareCodePoints(GRINNING, GRINNING)).toBe(0);
|
||||
expect(compareCodePoints("a", "a")).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps a prefix before its own extension", () => {
|
||||
expect(compareCodePoints("ab", "abc")).toBe(-1);
|
||||
expect(compareCodePoints("abc", "ab")).toBe(1);
|
||||
@@ -39,9 +33,4 @@ describe("uniqueSorted", () => {
|
||||
GRINNING,
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves the inferred literal type", () => {
|
||||
const values: ReadonlyArray<"a" | "b"> = ["b", "a", "b"];
|
||||
expect(uniqueSorted(values)).toEqual(["a", "b"]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -90,14 +90,6 @@ describe("jsonValueSchema depth bound", () => {
|
||||
).toBe(false);
|
||||
expect(jsonValueSchema.safeParse({ a: 1n }).success).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts ordinary nested JSON", () => {
|
||||
expect(
|
||||
jsonValueSchema.safeParse({
|
||||
list: [1, "two", null, true, { deep: { further: [{}] } }],
|
||||
}).success,
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves prototype-named members without prototype mutation", () => {
|
||||
|
||||
@@ -82,14 +82,4 @@ describe("process observation vocabulary", () => {
|
||||
expect(observations[3]?.captured_at_ms).toBeNull();
|
||||
expect(observations[4]?.captured_at_ms).toBeNull();
|
||||
});
|
||||
|
||||
it("returns no observation for a missing collection record", () => {
|
||||
expect(
|
||||
projectProcessObservation(capture, {
|
||||
collection: "frames",
|
||||
index: 1,
|
||||
capture_order: 10,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,21 +6,12 @@ import {
|
||||
type WindowsProcessTreeHost,
|
||||
} from "./ProcessOwnership.js";
|
||||
import {
|
||||
createSystemProcessOwnershipHost,
|
||||
observeOwnedProcessGroup,
|
||||
observeOwnedProcessLineage,
|
||||
} from "./ProcessOwnershipObservation.js";
|
||||
import { host, ownership } from "./ProcessOwnership.fixture.js";
|
||||
|
||||
describe("owned process-group cleanup validation: ownership and lineage", () => {
|
||||
it("builds a host seam from the injected platform and environment", async () => {
|
||||
const host = createSystemProcessOwnershipHost("win32", {
|
||||
PATH: "/injected/path",
|
||||
});
|
||||
expect(host.platform).toBe("win32");
|
||||
await expect(host.listProcesses()).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("fails closed when a descendant in another process group lacks the token", async () => {
|
||||
const adapter: ProcessOwnershipHost = {
|
||||
listProcesses: () =>
|
||||
|
||||
Reference in New Issue
Block a user