Skip to content
15 changes: 9 additions & 6 deletions tests/account_diagnosis_targets_validation.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";

const workerSource = readFileSync(new URL("../web/strategy-switch-console/worker.js", import.meta.url), "utf8");
assert.match(workerSource, /"schwab\.primary": Object\.freeze\(/);
assert.match(workerSource, /"firstrade\.primary": Object\.freeze\(/);
assert.match(workerSource, /recheckRepository: "QuantStrategyLab\/CharlesSchwabPlatform"/);
assert.match(workerSource, /recheckRepository: "QuantStrategyLab\/FirstradePlatform"/);
assert.match(workerSource, /recheckWorkflow: "runtime-target-lifecycle\.yml"/);
const diagnosisTargetsSource = [
readFileSync(new URL("../web/strategy-switch-console/worker.js", import.meta.url), "utf8"),
readFileSync(new URL("../web/strategy-switch-console/application/account_diagnosis/constants.js", import.meta.url), "utf8"),
].join("\n");
assert.match(diagnosisTargetsSource, /"schwab\.primary": Object\.freeze\(/);
assert.match(diagnosisTargetsSource, /"firstrade\.primary": Object\.freeze\(/);
assert.match(diagnosisTargetsSource, /recheckRepository: "QuantStrategyLab\/CharlesSchwabPlatform"/);
assert.match(diagnosisTargetsSource, /recheckRepository: "QuantStrategyLab\/FirstradePlatform"/);
assert.match(diagnosisTargetsSource, /recheckWorkflow: "runtime-target-lifecycle\.yml"/);
console.log("account_diagnosis_targets_validation: PASS (schwab.primary + firstrade.primary admitted)");
18 changes: 12 additions & 6 deletions tests/account_facts_readonly_extract_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ const workerSource = await readFile(
new URL("../web/strategy-switch-console/worker.js", import.meta.url),
"utf8",
);
const supportSource = await readFile(
new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url),
"utf8",
);
const readSource = await readFile(
new URL("../web/strategy-switch-console/application/account_facts/read.js", import.meta.url),
"utf8",
);
const wiredSource = `${workerSource}\n${supportSource}`;

assert.equal(
workerSource.includes('from "./application/account_facts/read.js"'),
workerSource.includes('from "./application/account_facts/read.js"')
|| supportSource.includes('from "../account_facts/read.js"')
|| supportSource.includes("from '../account_facts/read.js'"),
true,
"Worker imports the B10-a account-facts read module",
"Worker stack imports the B10-a account-facts read module",
);
assert.match(workerSource, /\/api\/account-facts"/);
assert.match(workerSource, /\/api\/account-facts\/history"/);
assert.match(workerSource, /async function syncAccountFactsResponse/);
assert.equal(
assert.match(wiredSource, /\/api\/account-facts"/);
assert.match(wiredSource, /\/api\/account-facts\/history"/);
assert.match(supportSource, /async function syncAccountFactsResponse/);assert.equal(
/transactionSync/.test(readSource),
false,
"read module must not open Durable Object transactions",
Expand Down
21 changes: 14 additions & 7 deletions tests/account_facts_sync_extract_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@ const workerSource = await readFile(
new URL("../web/strategy-switch-console/worker.js", import.meta.url),
"utf8",
);
const supportSource = await readFile(
new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url),
"utf8",
);
const syncSource = await readFile(
new URL("../web/strategy-switch-console/application/account_facts/sync.js", import.meta.url),
"utf8",
);
const wiredSource = `${workerSource}\n${supportSource}`;

assert.equal(
workerSource.includes('from "./application/account_facts/sync.js"'),
workerSource.includes('from "./application/account_facts/sync.js"')
|| supportSource.includes('from "../account_facts/sync.js"')
|| supportSource.includes("from '../account_facts/sync.js'"),
true,
"Worker imports the B10-b account-facts sync module",
"Worker stack imports the B10-b account-facts sync module",
);
assert.match(workerSource, /\/api\/account-facts\/sync"/);
assert.match(workerSource, /async function syncAccountFactsResponse/);
assert.match(workerSource, /syncAccountFactsResponseImpl/);
assert.match(wiredSource, /\/api\/account-facts\/sync"/);
assert.match(supportSource, /async function syncAccountFactsResponse/);
assert.match(wiredSource, /syncAccountFactsResponseImpl/);
const syncSourceNoComments = syncSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
assert.equal(
/transactionSync/.test(syncSourceNoComments),
Expand All @@ -40,11 +47,11 @@ assert.equal(
true,
"sync still issues account_facts_put via injected repository",
);
assert.match(workerSource, /async function syncAccountPeriodReturnResponse/);
assert.match(wiredSource, /async function syncAccountPeriodReturnResponse|syncAccountPeriodReturnResponse/);
assert.equal(
/syncAccountPeriodReturnResponse/.test(syncSource),
false,
"B10-b smallest slice: period-return sync stays in worker",
"B10-b smallest slice: period-return sync stays outside sync.js",
);

function json(payload, status = 200) {
Expand Down
15 changes: 9 additions & 6 deletions tests/account_facts_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1960,12 +1960,15 @@ for (const platform of ["longbridge", "ibkr", "schwab", "firstrade"]) {
}

const workerSource = readFileSync(join(root, "web/strategy-switch-console/worker.js"), "utf8");
assert.match(workerSource, /account_facts_put/);
assert.match(workerSource, /account_facts_history_read|account_facts_daily/);
assert.match(workerSource, /account_facts_stale_write|decideAccountFactsPut/);
assert.doesNotMatch(workerSource, /writeConfigJson\(env, accountFactsStorageKey/);
assert.doesNotMatch(workerSource, /account_facts:\$\{platform\}/);
assert.match(workerSource, /\/api\/account-facts\/history/);
const supportSource = readFileSync(join(root, "web/strategy-switch-console/application/worker/runtime_support.js"), "utf8");
const durableSource = readFileSync(join(root, "web/strategy-switch-console/application/runtime_instances/durable_object.js"), "utf8");
const wiredSource = `${workerSource}\n${supportSource}\n${durableSource}`;
assert.match(wiredSource, /account_facts_put/);
assert.match(wiredSource, /account_facts_history_read|account_facts_daily/);
assert.match(wiredSource, /account_facts_stale_write|decideAccountFactsPut/);
assert.doesNotMatch(wiredSource, /writeConfigJson\(env, accountFactsStorageKey/);
assert.doesNotMatch(wiredSource, /account_facts:\$\{platform\}/);
assert.match(wiredSource, /\/api\/account-facts\/history/);

await mf.dispose();
console.log("account_facts_validation ok");
Expand Down
9 changes: 8 additions & 1 deletion tests/console_gap_contract_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,14 @@ for (const reason of controlReasons.filter(r => r !== "available")) {
}
const controlSource = readFileSync(new URL("../web/strategy-switch-console/application/console_api/run_controls.js", import.meta.url), "utf8");
const workerSource = readFileSync(new URL("../web/strategy-switch-console/worker.js", import.meta.url), "utf8");
const supportSource = readFileSync(new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url), "utf8");
const profileStateSources = [workerSource, supportSource]
.map((source) => {
const start = source.indexOf(" profileState: async () => {");
return start < 0 ? "" : source.slice(start).split("\n });")[0];
})
.join("\n");
const reasons = [...controlSource.matchAll(/(?:blocked\(|reason: )"([a-z_]+)"/g),
...workerSource.slice(workerSource.indexOf(" profileState: async () => {")).split("\n });")[0].matchAll(/reason: "([a-z_]+)"/g)].map(m => m[1]);
...profileStateSources.matchAll(/reason: "([a-z_]+)"/g)].map(m => m[1]);
assert.deepEqual([...new Set(reasons)].sort(), [...controlReasons].sort(), "handoff reasons cover every current control gate");
console.log("console_gap_contract_validation: PASS (M0 12, currency 7, ten identities, failure/unknown/control semantics)");
16 changes: 13 additions & 3 deletions tests/overview_fx_proxy_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ const workerSource = await fs.readFile(
new URL("../web/strategy-switch-console/worker.js", import.meta.url),
"utf8",
);
const supportSource = await fs.readFile(
new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url),
"utf8",
);
const fxSource = await fs.readFile(
new URL("../web/strategy-switch-console/infrastructure/fx/overview_fx.js", import.meta.url),
"utf8",
);
assert.match(workerSource, /connect-src 'self'/, "CSP stays same-origin; Frankfurter is not widened into connect-src");
assert.match(supportSource, /connect-src 'self'/, "CSP stays same-origin; Frankfurter is not widened into connect-src");
assert.equal(fxSource.includes("api.frankfurter.dev"), true, "FX module retains the fixed Frankfurter upstream");
assert.equal(workerSource.includes("infrastructure/fx/overview_fx.js"), true, "Worker imports the FX module");
assert.equal(/connect-src[^;]*frankfurter/.test(workerSource), false, "browser CSP must not allow frankfurter");
assert.equal(
workerSource.includes("infrastructure/fx/overview_fx.js")
|| supportSource.includes("infrastructure/fx/overview_fx.js"),
true,
"Worker stack imports the FX module",
);
assert.equal(/connect-src[^;]*frankfurter/.test(supportSource), false, "browser CSP must not allow frankfurter");
assert.equal(/connect-src[^;]*frankfurter/.test(workerSource), false, "facade CSP must not allow frankfurter");

__test.resetOverviewFxCache();
const frankfurterBody = JSON.stringify({
Expand Down
21 changes: 14 additions & 7 deletions tests/owner_decision_extract_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,28 @@ const workerSource = await readFile(
new URL("../web/strategy-switch-console/worker.js", import.meta.url),
"utf8",
);
const supportSource = await readFile(
new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url),
"utf8",
);
const moduleSource = await readFile(
new URL("../web/strategy-switch-console/application/approval/owner_decisions.js", import.meta.url),
"utf8",
);
const wiredSource = `${workerSource}\n${supportSource}`;

assert.equal(
workerSource.includes('from "./application/approval/owner_decisions.js"'),
workerSource.includes('from "./application/approval/owner_decisions.js"')
|| supportSource.includes('from "../approval/owner_decisions.js"')
|| supportSource.includes("from '../approval/owner_decisions.js'"),
true,
"Worker imports the B10-c owner-decision module",
"Worker stack imports the B10-c owner-decision module",
);
assert.match(workerSource, /\/api\/owner-decisions"/);
assert.match(workerSource, /ownerDecisionQueueResponseImpl/);
assert.match(workerSource, /recordOwnerDecisionResponseImpl/);
assert.match(workerSource, /async function ownerDecisionQueueResponse/);
assert.match(workerSource, /async function recordOwnerDecisionResponse/);
assert.match(wiredSource, /\/api\/owner-decisions"/);
assert.match(wiredSource, /ownerDecisionQueueResponseImpl/);
assert.match(wiredSource, /recordOwnerDecisionResponseImpl/);
assert.match(supportSource, /async function ownerDecisionQueueResponse/);
assert.match(supportSource, /async function recordOwnerDecisionResponse/);

const moduleNoComments = moduleSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
assert.equal(
Expand Down
14 changes: 12 additions & 2 deletions tests/reconciliation_material_presentation_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ import { recoveryMaterialPresentation, currentReconciliationObservationPresentat
// Exercise the production aggregation/freshness functions with in-memory inputs.
// No Worker, storage adapter, KV, server, or network is instantiated.
const workerText = readFileSync(new URL("../web/strategy-switch-console/worker.js", import.meta.url), "utf8");
const runtimeSupportText = readFileSync(
new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url),
"utf8",
);
function productionFunction(name, dependencies = {}) {
const start = workerText.search(new RegExp(`(?:async )?function ${name}\\(`));
const pattern = new RegExp(`(?:export )?(?:async )?function ${name}\\(`);
let source = workerText;
let start = source.search(pattern);
if (start < 0) {
source = runtimeSupportText;
start = source.search(pattern);
}
assert.ok(start >= 0, name);
const code = workerText.slice(start, workerText.indexOf("\n}", start) + 2);
const code = source.slice(start, source.indexOf("\n}", start) + 2).replace(/^export\s+/, "");
return new Function(...Object.keys(dependencies), `return (${code});`)(...Object.values(dependencies));
}
const now = Date.parse("2001-10-17T04:05:00Z");
Expand Down
34 changes: 22 additions & 12 deletions tests/research_promotion_application_extract_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,36 @@ const workerSource = await readFile(
new URL("../web/strategy-switch-console/worker.js", import.meta.url),
"utf8",
);
const supportSource = await readFile(
new URL("../web/strategy-switch-console/application/worker/runtime_support.js", import.meta.url),
"utf8",
);
const durableSource = await readFile(
new URL("../web/strategy-switch-console/application/runtime_instances/durable_object.js", import.meta.url),
"utf8",
);
const moduleSource = await readFile(
new URL("../web/strategy-switch-console/application/research_promotion/applications.js", import.meta.url),
"utf8",
);
const wiredSource = `${workerSource}\n${supportSource}`;

assert.equal(
workerSource.includes('from "./application/research_promotion/applications.js"'),
workerSource.includes('from "./application/research_promotion/applications.js"')
|| supportSource.includes('from "../research_promotion/applications.js"')
|| supportSource.includes("from '../research_promotion/applications.js'"),
true,
"Worker imports the B10-d research-promotion applications module",
"Worker stack imports the B10-d research-promotion applications module",
);
assert.match(workerSource, /\/api\/research-promotion-applications"/);
assert.match(workerSource, /\/api\/internal\/research-promotion-application\//);
assert.match(workerSource, /researchPromotionApplicationResponseImpl/);
assert.match(workerSource, /researchPromotionApplicationInternalResponseImpl/);
assert.match(workerSource, /async function researchPromotionApplicationResponse/);
assert.match(workerSource, /async function researchPromotionApplicationInternalResponse/);
assert.match(workerSource, /function applicationIdFromPath/);
assert.match(workerSource, /function validateV7PaperApplicationReadback/);
assert.match(workerSource, /CREATE TABLE IF NOT EXISTS research_promotion_applications/);

assert.match(wiredSource, /\/api\/research-promotion-applications"/);
assert.match(wiredSource, /\/api\/internal\/research-promotion-application\//);
assert.match(wiredSource, /researchPromotionApplicationResponseImpl/);
assert.match(wiredSource, /researchPromotionApplicationInternalResponseImpl/);
assert.match(supportSource, /async function researchPromotionApplicationResponse/);
assert.match(supportSource, /async function researchPromotionApplicationInternalResponse/);
assert.match(supportSource, /function applicationIdFromPath|applicationIdFromPath/);
assert.match(supportSource, /function validateV7PaperApplicationReadback|validateV7PaperApplicationReadback/);
assert.match(durableSource, /CREATE TABLE IF NOT EXISTS research_promotion_applications/);
const moduleNoComments = moduleSource.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "");
assert.equal(
/transactionSync/.test(moduleNoComments),
Expand Down
5 changes: 4 additions & 1 deletion tests/runtime_instances_worker_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ try {
mf = new Miniflare({ ...options, durableObjectsPersist: false,
durableObjects: { STRATEGY_SWITCH_RUNTIME_INSTANCES: { className: "FailingRuntimeInstances", useSQLite: true } },
script: source + `\nexport class FailingRuntimeInstances extends RuntimeInstances {
constructor(ctx) { super(ctx); this.sql.exec("CREATE TRIGGER IF NOT EXISTS fail_history BEFORE INSERT ON instance_history WHEN NEW.revision = 2 BEGIN SELECT RAISE(ABORT, 'fixture rollback'); END"); }
constructor(ctx, env) {
super(ctx, env);
this.sql.exec("CREATE TRIGGER IF NOT EXISTS fail_history BEFORE INSERT ON instance_history WHEN NEW.revision = 2 BEGIN SELECT RAISE(ABORT, 'fixture rollback'); END");
}
}`,
});
assert.equal((await call({ action: "initialize", expected_revision: 0, confirm: "IMPORT_EXISTING_CONFIG" })).status, 200);
Expand Down
11 changes: 9 additions & 2 deletions tests/ux1_research_worker_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,15 @@ try {

assert.equal(__test.ux1CalculatorDeadlineMs, 30000);
assert.equal(__test.ux1CalculatorMaxBytes, 65536);
const workerSource = await readFile(new URL("../web/strategy-switch-console/worker.js", import.meta.url), "utf8");
const previewFn = workerSource.slice(workerSource.indexOf("async function ux1PreviewPost"), workerSource.indexOf("async function ux1IntentPost"));
// Implementation lives in application/ux1/research.js; worker.js only imports and routes.
const ux1ResearchSource = await readFile(
new URL("../web/strategy-switch-console/application/ux1/research.js", import.meta.url),
"utf8",
);
const previewStart = ux1ResearchSource.indexOf("async function ux1PreviewPost");
const intentStart = ux1ResearchSource.indexOf("async function ux1IntentPost");
assert.equal(previewStart >= 0 && intentStart > previewStart, true);
const previewFn = ux1ResearchSource.slice(previewStart, intentStart);
assert.equal(previewFn.includes("readUx1CalculatorExchange(binding, canonicalJson(calculatorRequest))"), true);
assert.equal(previewFn.includes("deadlineMs"), false);
assert.equal(previewFn.includes("maxBytes"), false);
Expand Down
Loading
Loading