Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/control_plane_ts/python_read_consumer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {spawnSync} from "node:child_process";
import {closeSync, mkdtempSync, openSync, rmSync, writeFileSync} from "node:fs";
import {tmpdir} from "node:os";
import {join} from "node:path";
import {resolveTestPython} from "../../scripts/test-python.mjs";

// Keep the complete JSON on stdin, with a finite source independent of pipe EOF.
// Large synchronous pipe writes can strand the consumer in stdin.read() under
// the concurrent conformance suite before any product operation is reached.
export function runPythonReadConsumer(consumer: string, source: unknown) {
const directory = mkdtempSync(join(tmpdir(), "loopx-python-read-"));
try {
const path = join(directory, "source.json");
writeFileSync(path, JSON.stringify(source), {encoding: "utf8", mode: 0o600});
const input = openSync(path, "r");
try {
return spawnSync(resolveTestPython(), ["-c", consumer], {
encoding: "utf8", timeout: 90_000, stdio: [input, "pipe", "pipe"],
});
} finally {
closeSync(input);
}
} finally {
rmSync(directory, {recursive: true, force: true});
}
}
8 changes: 2 additions & 6 deletions tests/control_plane_ts/succession_read_conformance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import assert from "node:assert/strict";
import {spawnSync} from "node:child_process";
import test from "node:test";
import type {AuthorityStoreConformanceFactory} from "./authority_store_conformance.ts";
import {productionScaleSuccessionFixture} from "./production_scale_coordination_fixture.ts";
import {validateCoordinationTodoReadModel} from "../../loopx/control_plane/coordination/coordination_projection.ts";
import {resolveTestPython} from "../../scripts/test-python.mjs";

const PYTHON = resolveTestPython();
import {runPythonReadConsumer} from "./python_read_consumer.ts";

// Exercise the shipped Python consumer → typed policy, not a second test reducer.
const CONSUMER = `
Expand All @@ -32,8 +29,7 @@ export function registerSuccessionReadConformance(name: string, factory: Authori
next_projection: projection, events: [], receipts: []})).status, "applied");
const before = await store.loadAuthority();
assert.equal(before.status, "loaded");
const child = spawnSync(PYTHON, ["-c", CONSUMER], {encoding: "utf8", timeout: 90_000,
input: JSON.stringify({todos: before.head.todos, cases})});
const child = runPythonReadConsumer(CONSUMER, {todos: before.head.todos, cases});
assert.equal(child.status, 0, child.stderr);
const actual = JSON.parse(child.stdout);
assert.deepEqual(actual.inferred_source, {gap: 0, gates: [], closure: false});
Expand Down
8 changes: 2 additions & 6 deletions tests/control_plane_ts/todo_consumer_scope_conformance.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import assert from "node:assert/strict";
import {spawnSync} from "node:child_process";
import test from "node:test";
import type {JsonObject} from "../../loopx/control_plane/effect_program.ts";
import type {AuthorityStoreConformanceFactory} from "./authority_store_conformance.ts";
import {productionScaleConsumerScopeFixture} from "./production_scale_coordination_fixture.ts";
import {resolveTestPython} from "../../scripts/test-python.mjs";

const PYTHON = resolveTestPython();
import {runPythonReadConsumer} from "./python_read_consumer.ts";

// The actual Python read consumer still hosts rendering; policy runs in TS.
const CONSUMER = `
Expand Down Expand Up @@ -45,8 +42,7 @@ export function registerTodoConsumerScopeConformance(name: string, factory: Auth
next_projection: projection, events: [], receipts: []})).status, "applied");
const before = await store.loadAuthority(); assert.equal(before.status, "loaded");
if (before.status !== "loaded") return;
const child = spawnSync(PYTHON, ["-c", CONSUMER], {encoding: "utf8", timeout: 90_000,
input: JSON.stringify({todos: before.head.todos, cases})});
const child = runPythonReadConsumer(CONSUMER, {todos: before.head.todos, cases});
assert.equal(child.status, 0, child.stderr);
const result = JSON.parse(child.stdout);
const expected = ["todo_scope_explicit_action", "todo_scope_explicit_gate", "todo_scope_global"];
Expand Down
Loading