feat(browser): trace captured website source-map locations (#897)
* refactor(browser): share captured-script acquisition boundaries Reuse stable capture/source acquisition and identity validation for module and source-map analysis. Preserve host I/O, malformed input, unavailable source and digest mismatch diagnostics. Refs #851 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * feat(browser): trace captured website source-map locations Refs #851. Preserve selected capture/map byte identity, duplicate mappings and embedded source evidence through the pinned upstream codec. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * test(browser): verify source-map artifacts and synchronize generated contracts Cover byte-preserving map reads and actionable filesystem constraints. Refresh generated public schemas and metadata on current main. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): preserve inert source-map URL context The selected URL is local codec context and grants no transport authority. Preserve its reported text and verify normal/userinfo contexts through real public interfaces, alongside independent manifest byte identity. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
This commit is contained in:
@@ -187,7 +187,7 @@ export const spawnOwnedProviderProcess = async (
|
||||
/**
|
||||
* Supervises only generic process resources; wire protocol remains adapter-owned.
|
||||
*
|
||||
* Output retention is bounded per stream while byte totals remain exact. Stop
|
||||
* Output retention is complete per stream; adapters own resource budgets. Stop
|
||||
* first honors token-verified group cleanup when supplied, otherwise it uses a
|
||||
* bounded TERM-to-KILL escalation for a directly owned child.
|
||||
*/
|
||||
@@ -199,6 +199,8 @@ export class ProviderProcessSupervisor {
|
||||
readonly code: number | null;
|
||||
readonly signal: NodeJS.Signals | null;
|
||||
}>();
|
||||
readonly #outputClose = deferred<void>();
|
||||
#outputClosed = false;
|
||||
readonly #onStdout = (chunk: Buffer | string): void => {
|
||||
this.#capture("stdout", this.#stdout, chunk);
|
||||
};
|
||||
@@ -216,6 +218,8 @@ export class ProviderProcessSupervisor {
|
||||
signal: NodeJS.Signals | null,
|
||||
): void => {
|
||||
this.#recordExit(code, signal);
|
||||
this.#outputClosed = true;
|
||||
this.#outputClose.resolve(undefined);
|
||||
};
|
||||
readonly #onError = (cause: Error): void => {
|
||||
this.#options.onDiagnostic?.({ type: "error", message: cause.message });
|
||||
@@ -252,18 +256,20 @@ export class ProviderProcessSupervisor {
|
||||
|
||||
/** Wait for process exit up to a caller-owned bounded interval. */
|
||||
async waitForExit(timeoutMs: number): Promise<boolean> {
|
||||
if (this.#exitObservation !== undefined) return true;
|
||||
let timer: NodeJS.Timeout | undefined;
|
||||
try {
|
||||
return await Promise.race([
|
||||
this.#exit.promise.then(() => true),
|
||||
new Promise<boolean>((resolve) => {
|
||||
timer = setTimeout(() => resolve(false), Math.max(0, timeoutMs));
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timer !== undefined) clearTimeout(timer);
|
||||
}
|
||||
return waitForProcessEvent(
|
||||
this.#exitObservation !== undefined,
|
||||
this.#exit.promise,
|
||||
timeoutMs,
|
||||
);
|
||||
}
|
||||
|
||||
/** Wait until the producer has closed its output streams; exit alone does not prove complete output. */
|
||||
async waitForOutputClose(timeoutMs: number): Promise<boolean> {
|
||||
return waitForProcessEvent(
|
||||
this.#outputClosed,
|
||||
this.#outputClose.promise,
|
||||
timeoutMs,
|
||||
);
|
||||
}
|
||||
|
||||
/** Stop an owned process once; concurrent callers share the same escalation. */
|
||||
@@ -442,3 +448,22 @@ const waitForSpawn = (child: ChildProcess): Promise<void> =>
|
||||
child.once("spawn", onSpawn);
|
||||
child.once("error", onError);
|
||||
});
|
||||
|
||||
const waitForProcessEvent = async (
|
||||
observed: boolean,
|
||||
event: Promise<unknown>,
|
||||
timeoutMs: number,
|
||||
): Promise<boolean> => {
|
||||
if (observed) return true;
|
||||
let timer: NodeJS.Timeout | undefined;
|
||||
try {
|
||||
return await Promise.race([
|
||||
event.then(() => true),
|
||||
new Promise<boolean>((resolve) => {
|
||||
timer = setTimeout(() => resolve(false), Math.max(0, timeoutMs));
|
||||
}),
|
||||
]);
|
||||
} finally {
|
||||
if (timer !== undefined) clearTimeout(timer);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user