fix: 通过主工作区契约委派 tran
This commit is contained in:
@@ -226,7 +226,7 @@ function resourceMaterializationEnv(env: NodeJS.ProcessEnv, runId: string, attem
|
||||
|
||||
function resourceEnvForMaterialized(env: NodeJS.ProcessEnv, materialized: Awaited<ReturnType<typeof materializeResourceBundle>>): NodeJS.ProcessEnv | undefined {
|
||||
if (!materialized) return undefined;
|
||||
const sanitized = { ...env };
|
||||
const sanitized = { ...env, AGENTRUN_WORKSPACE_PATH: materialized.workspacePath };
|
||||
delete sanitized.AGENTRUN_RESOURCE_CREDENTIAL_PATH;
|
||||
let next: NodeJS.ProcessEnv | undefined = sanitized;
|
||||
if (materialized.binPath) {
|
||||
|
||||
@@ -196,6 +196,8 @@ process.exit(1);
|
||||
assert.equal(assemblyRunnerResult.commandsProcessed, 2);
|
||||
const assemblyInputs = (await readTextIfExists(assemblyInputFile)).trim().split("\n").filter(Boolean).map((line) => JSON.parse(line) as JsonRecord);
|
||||
assert.equal(assemblyInputs.length, 2);
|
||||
assert.equal(assemblyInputs[0]?.workspacePath, assemblyInputs[0]?.cwd, "backend tool env must identify the materialized primary workspace explicitly");
|
||||
assert.equal(assemblyInputs[1]?.workspacePath, assemblyInputs[1]?.cwd, "continued turns must preserve the primary workspace env contract");
|
||||
const firstAssemblyInput = turnInputText(assemblyInputs[0]);
|
||||
const secondAssemblyInput = turnInputText(assemblyInputs[1]);
|
||||
assert.match(firstAssemblyInput, /HWLAB v0\.2 runtime prompt self-test/u);
|
||||
|
||||
@@ -31,12 +31,32 @@ const selfTest: SelfTestCase = async (context) => {
|
||||
assert.equal(applyPatch.startsWith("#!/bin/sh\n"), true, "tools/apply_patch must be a shebang helper copied with runner tools");
|
||||
assert.equal(agentrunGit.startsWith("#!/usr/bin/env bun\n"), true, "tools/agentrun-git must be a shebang executable discovered by gitbundle tools");
|
||||
assert.equal(tran.includes("scripts/tran"), true, "tools/tran must delegate to the primary UniDesk workspace implementation");
|
||||
assert.equal(tran.includes("AGENTRUN_WORKSPACE_PATH"), true, "tools/tran must use the explicit primary workspace contract");
|
||||
assert.equal(tran.includes("UNIDESK_TRAN_REPO_ROOT"), true, "tools/tran must bind the shared implementation to the primary workspace");
|
||||
assert.equal(tran.includes("dirname -- \"$0\""), false, "tools/tran must not infer the primary workspace from an installed shim path");
|
||||
assert.equal(tran.includes("parseRoute"), false, "tools/tran must not carry a second route parser");
|
||||
assert.equal(tran.includes("does not support Windows routes"), false, "tools/tran must not reject shared Windows routes");
|
||||
assert.equal(agentrunGit.includes("GIT_TERMINAL_PROMPT"), true, "tools/agentrun-git must disable interactive git prompts");
|
||||
assert.equal(agentrunGit.includes("AGENTRUN_GIT_DIRECT_HOSTS"), true, "tools/agentrun-git must expose direct host policy");
|
||||
|
||||
const primaryWorkspace = path.join(context.tmp, "tran-primary-workspace");
|
||||
const primaryScripts = path.join(primaryWorkspace, "scripts");
|
||||
await mkdir(primaryScripts, { recursive: true });
|
||||
await writeFile(path.join(primaryScripts, "ssh-cli.ts"), "// UniDesk shared tran entrypoint\n", "utf8");
|
||||
await writeFile(path.join(primaryScripts, "tran"), "#!/bin/sh\nprintf '%s\\n' \"$UNIDESK_TRAN_REPO_ROOT\" \"$*\"\n", "utf8");
|
||||
await chmod(path.join(primaryScripts, "tran"), 0o755);
|
||||
const installedBin = path.join(context.tmp, "installed-resource-bin");
|
||||
await mkdir(installedBin, { recursive: true });
|
||||
const installedTran = path.join(installedBin, "tran");
|
||||
await writeFile(installedTran, `#!/bin/sh\nexec '${path.join(context.root, "tools/tran")}' \"$@\"\n`, "utf8");
|
||||
await chmod(installedTran, 0o755);
|
||||
const delegatedTran = await execFileAsync(installedTran, ["TEST:win", "cmd", "cd"], { cwd: context.tmp, env: { ...process.env, AGENTRUN_WORKSPACE_PATH: primaryWorkspace } });
|
||||
assert.deepEqual(delegatedTran.stdout.trim().split("\n"), [primaryWorkspace, "TEST:win cmd cd"]);
|
||||
await assert.rejects(
|
||||
() => execFileAsync(installedTran, ["--help"], { cwd: context.tmp, env: { ...process.env, AGENTRUN_WORKSPACE_PATH: undefined } }),
|
||||
(error) => error instanceof Error && "stderr" in error && String(error.stderr).includes("runner did not provide an absolute primary workspace path"),
|
||||
);
|
||||
|
||||
const patchHelp = await execFileAsync(path.join(context.root, "tools/apply_patch"), ["--help"], { cwd: context.root, timeout: 10_000 });
|
||||
assert.equal(patchHelp.stdout.includes("reads *** Begin Patch format"), true);
|
||||
const agentrunGitHelp = await execFileAsync(path.join(context.root, "tools/agentrun-git"), ["--help"], { cwd: context.root, timeout: 10_000 });
|
||||
|
||||
@@ -75,7 +75,7 @@ for await (const line of rl) {
|
||||
continue;
|
||||
}
|
||||
if (message.method === "turn/start") {
|
||||
if (process.env.AGENTRUN_FAKE_CODEX_TURN_INPUT_FILE) appendFileSync(process.env.AGENTRUN_FAKE_CODEX_TURN_INPUT_FILE, `${JSON.stringify({ threadId: message.params?.threadId ?? null, input: message.params?.input ?? null, model: message.params?.model ?? null, effort: message.params?.effort ?? null })}\n`);
|
||||
if (process.env.AGENTRUN_FAKE_CODEX_TURN_INPUT_FILE) appendFileSync(process.env.AGENTRUN_FAKE_CODEX_TURN_INPUT_FILE, `${JSON.stringify({ threadId: message.params?.threadId ?? null, input: message.params?.input ?? null, model: message.params?.model ?? null, effort: message.params?.effort ?? null, workspacePath: process.env.AGENTRUN_WORKSPACE_PATH ?? null, cwd: process.cwd() })}\n`);
|
||||
if (mode === "reject-unexpected-model" && (observedThreadModel || Object.hasOwn(message.params ?? {}, "model"))) {
|
||||
respond(message.id, null, { code: -32000, message: "turn/start unexpectedly included model" });
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user