Files
reverse-engineering-anything/tests/composition/setup-lifecycle/passiveObservationConfig.test.ts
T
morluto b8a9da0c0f refactor(mcp): make analysis states unrepresentable (#468)
* refactor(config): parse capability settings into exact states

* refactor(runtime): encode replay and process outcomes exactly

* refactor: make analysis states unrepresentable

* refactor(mcp): register canonical schemas with SDK

* fix: preserve capability and catalog invariants

* fix(build): remove stale compiled modules

* fix(replay): update real verifier policy dependency

* fix(package): verify the complete MCP catalog

* fix(test): supply complete replay reload policy

* refactor(contracts): centralize output schema lookup

* refactor(mcp): delegate protocol boundaries to SDK

* fix(browser): approve real source capture

* fix(mcp): preserve catalog guidance
2026-08-10 02:28:11 +08:00

154 lines
4.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parseConfig } from "../../../src/config.js";
describe("passive browser observation policy", () => {
it("requires both endpoint and origin scopes when enabled", () => {
expect(
parseConfig({
REA_BROWSER_OBSERVE_ENABLED: "true",
REA_BROWSER_ALLOWED_ORIGINS_JSON: '["https://app.example.test"]',
}).ok,
).toBe(false);
expect(
parseConfig({
REA_BROWSER_OBSERVE_ENABLED: "true",
REA_BROWSER_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9222"]',
}).ok,
).toBe(false);
});
it("parses one enabled policy and drops inactive settings", () => {
expect(
parseConfig({
REA_BROWSER_OBSERVE_ENABLED: "true",
REA_BROWSER_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9222"]',
REA_BROWSER_ALLOWED_ORIGINS_JSON: '["https://app.example.test"]',
}),
).toMatchObject({
ok: true,
value: {
browserObservationPolicy: {
status: "enabled",
cdpEndpoints: ["http://127.0.0.1:9222"],
allowedOrigins: ["https://app.example.test"],
},
},
});
expect(
parseConfig({
REA_BROWSER_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9222"]',
REA_BROWSER_ALLOWED_ORIGINS_JSON: '["https://ignored.example.test"]',
}),
).toMatchObject({
ok: true,
value: { browserObservationPolicy: { status: "disabled" } },
});
});
});
describe("passive Electron observation policy", () => {
it("requires both endpoint and file-root scopes when enabled", () => {
expect(
parseConfig({
REA_ELECTRON_OBSERVE_ENABLED: "true",
REA_ELECTRON_FILE_ROOTS_JSON: '["/tmp/electron-app"]',
}).ok,
).toBe(false);
expect(
parseConfig({
REA_ELECTRON_OBSERVE_ENABLED: "true",
REA_ELECTRON_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9223"]',
}).ok,
).toBe(false);
});
it("parses one enabled policy and drops inactive settings", () => {
expect(
parseConfig({
REA_ELECTRON_OBSERVE_ENABLED: "true",
REA_ELECTRON_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9223"]',
REA_ELECTRON_FILE_ROOTS_JSON: '["/tmp/electron-app"]',
}),
).toMatchObject({
ok: true,
value: {
electronObservationPolicy: {
status: "enabled",
cdpEndpoints: ["http://127.0.0.1:9223"],
fileRoots: ["/tmp/electron-app"],
},
},
});
expect(
parseConfig({
REA_ELECTRON_CDP_ENDPOINTS_JSON: '["http://127.0.0.1:9223"]',
REA_ELECTRON_FILE_ROOTS_JSON: '["/ignored/electron-app"]',
}),
).toMatchObject({
ok: true,
value: { electronObservationPolicy: { status: "disabled" } },
});
});
});
describe("passive V8 Inspector observation policy", () => {
const endpoint = {
REA_V8_INSPECTOR_OBSERVE_ENABLED: "true",
REA_V8_INSPECTOR_ENDPOINTS_JSON: '["http://127.0.0.1:9229"]',
} as const;
it("requires an endpoint and at least one target-location scope", () => {
expect(
parseConfig({
REA_V8_INSPECTOR_OBSERVE_ENABLED: "true",
REA_V8_INSPECTOR_FILE_ROOTS_JSON: '["/tmp/node-app"]',
}).ok,
).toBe(false);
expect(parseConfig(endpoint).ok).toBe(false);
});
it.each([
["files", { REA_V8_INSPECTOR_FILE_ROOTS_JSON: '["/tmp/node-app"]' }],
[
"origins",
{
REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON:
'["https://renderer.example.test"]',
},
],
[
"files-and-origins",
{
REA_V8_INSPECTOR_FILE_ROOTS_JSON: '["/tmp/node-app"]',
REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON:
'["https://renderer.example.test"]',
},
],
] as const)("parses the %s location variant", (scope, environment) => {
expect(parseConfig({ ...endpoint, ...environment })).toMatchObject({
ok: true,
value: {
v8InspectorObservationPolicy: {
status: "enabled",
locations: { scope },
},
},
});
});
it("drops inactive endpoint and location settings", () => {
expect(
parseConfig({
REA_V8_INSPECTOR_ENDPOINTS_JSON: '["http://127.0.0.1:9229"]',
REA_V8_INSPECTOR_FILE_ROOTS_JSON: '["/ignored/node-app"]',
REA_V8_INSPECTOR_ALLOWED_ORIGINS_JSON:
'["https://ignored.example.test"]',
}),
).toMatchObject({
ok: true,
value: { v8InspectorObservationPolicy: { status: "disabled" } },
});
});
});