Files
openclaw/scripts/lib/declaration-source-index.mts
T
Peter Steinberger b03d2e79e9 fix(sessions): prevent participant misattribution in Activity (#130986)
* fix(sessions): preserve participant identity and input provenance

Keep profile, agent, remote, observed, and legacy identities distinct in the existing participant table. Record accepted input at admission, including steering, instead of inferring a person from the session creator. Preserve historical membership and counts while leaving ambiguous profile timestamps unknown through stopped-writer Doctor migration.

Project full visibility-filtered person membership before preview limits so Activity does not misattribute channel identities or omit people outside the facepile. Keep participant membership separate from authorization and expose raw-selector ambiguity to memory operators.

Repair Doctor readiness reporting, generic Swift inline-union generation, direct-dispatch metadata handling, and fixture-owned database lifetimes. Verify namespace collisions, real provider input, accepted steering, visibility, backup/migration/reopen boundaries, native decoding, and the built-CLI lifecycle.

Fixes #130661

* fix(macos): isolate readiness and discovery lifecycles

Keep readiness fixtures private for their entire lifetime and give health readiness one deadline owner. Start and cancel slow host discovery with active discovery, not model construction.

Make native protocol, callback, onboarding, and process-cleanup tests observe their intended lifecycle phases without expanding deadlines or weakening assertions. Correct the documented signing default.

Validated with 1,839 parallel native tests, the release product build, causal negative controls, pinned Swift lint/format checks, and fresh isolated autoreview. Native production delta: -5 lines.

* docs(macos): clarify app profile isolation boundaries

* build(protocol): refresh generated Swift install models

* fix(protocol): preserve optional literal field presence

* fix(ci): bound SDK declarations and isolate test lifecycles

Discover the current declaration source graph in a joined child before normal eager emission, and track its complete source-bearing cache inputs. Repair shared jsdom focus teardown and native worker fixture request ordering without changing UI focus ownership or execution fallback policy.

* test(sessions): prove Goal participant upgrade boundaries
2026-08-28 06:04:18 -07:00

85 lines
3.4 KiB
TypeScript

import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { isDirectRunUrl } from "./direct-run.mjs";
/** Discover fresh declaration roots without retaining a compiler graph in the emitter. */
export function discoverDeclarationSources(tsconfig: string, entries: readonly string[]): string[] {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-declaration-sources-"));
const output = path.join(directory, "sources.json");
try {
// Joining the child releases its entire graph before tsdown creates its program.
// Use an artifact, not a buffered stdout payload proportional to the source tree.
const result = spawnSync(
process.execPath,
["--import", "tsx", fileURLToPath(import.meta.url), tsconfig, output, ...entries],
{ stdio: ["ignore", "inherit", "inherit"] },
);
if (result.error) {
throw result.error;
}
if (result.status !== 0) {
throw new Error(`Declaration source discovery failed (${result.signal ?? result.status})`);
}
const files: unknown = JSON.parse(fs.readFileSync(output, "utf8"));
if (
!Array.isArray(files) ||
!files.every((file): file is string => typeof file === "string") ||
!entries.every((entry) => files.includes(path.resolve(entry)))
) {
throw new Error("Declaration source discovery returned an incomplete source index");
}
return files;
} finally {
fs.rmSync(directory, { recursive: true, force: true });
}
}
if (isDirectRunUrl(process.argv[1], import.meta.url)) {
try {
const [tsconfig, output, ...entries] = process.argv.slice(2);
if (!tsconfig || !output || entries.length === 0) {
throw new Error("Expected a tsconfig, output path, and declaration entry sources");
}
// Only the discovery child loads TypeScript; the parent retains just file names.
const { default: ts } = await import("typescript");
const config = ts.getParsedCommandLineOfConfigFile(path.resolve(tsconfig), undefined, {
...ts.sys,
onUnRecoverableConfigFileDiagnostic(diagnostic) {
throw new Error(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
},
});
if (!config || config.errors.length > 0) {
throw new Error(
config?.errors
.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"))
.join("\n") ?? "Unable to read declaration configuration",
);
}
const roots = entries.map((entry) => path.resolve(entry));
const program = ts.createProgram({
rootNames: roots,
options: config.options,
projectReferences: config.projectReferences,
});
for (const entry of roots) {
if (!program.getSourceFile(entry)) {
throw new Error(`Missing declaration entry source: ${entry}`);
}
}
// The declaration plugin never requests generation for installed dependency files.
const files = program
.getSourceFiles()
.map((source) => path.resolve(source.fileName))
.filter((file) => !file.split(/[\\/]/u).includes("node_modules"))
.toSorted();
fs.writeFileSync(output, `${JSON.stringify(files)}\n`, { flag: "wx" });
} catch (error) {
console.error(error instanceof Error ? error.message : String(error));
console.error("[declaration-source-index] FAILED (exit 1)");
process.exitCode = 1;
}
}