Skip to content

Commit ae6557d

Browse files
fix(server): preserve lifecycle fixture settings and contain scratch paths
1 parent 55be24e commit ae6557d

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

‎apps/server/scripts/fixtures/seed-antigravity-lifecycle-proof.mjs‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,34 @@ import * as NodeURL from "node:url";
88
const root = NodeFS.realpathSync(
99
NodePath.resolve(NodePath.dirname(NodeURL.fileURLToPath(import.meta.url)), "../../../.."),
1010
);
11-
const scratch = process.argv[2];
12-
if (!scratch || !scratch.startsWith("/tmp/"))
11+
const canonicalPath = (path) => {
12+
const absolute = NodePath.resolve(path);
13+
let parent = absolute;
14+
while (true) {
15+
try {
16+
return NodePath.resolve(NodeFS.realpathSync(parent), NodePath.relative(parent, absolute));
17+
} catch (error) {
18+
if (error.code !== "ENOENT") throw error;
19+
if (NodeFS.lstatSync(parent, { throwIfNoEntry: false })?.isSymbolicLink())
20+
throw new Error("Fixture paths must not contain dangling symlinks", { cause: error });
21+
parent = NodePath.dirname(parent);
22+
}
23+
}
24+
};
25+
const tmp = NodeFS.realpathSync("/tmp");
26+
const scratch = process.argv[2] && canonicalPath(process.argv[2]);
27+
if (!scratch || !scratch.startsWith(tmp + NodePath.sep))
1328
throw new Error("Supply a scratch directory below /tmp");
29+
for (const name of [
30+
"scenario",
31+
"agy_acp_server.par",
32+
"localharness_external",
33+
"lifecycle.jsonl",
34+
"command-pids",
35+
]) {
36+
if (!canonicalPath(NodePath.join(scratch, name)).startsWith(tmp + NodePath.sep))
37+
throw new Error("Fixture files must stay below /tmp");
38+
}
1439
const settingsPath = NodePath.join(root, ".t3/userdata/settings.json");
1540
if (!NodeFS.realpathSync(settingsPath).startsWith(NodePath.join(root, ".t3/")))
1641
throw new Error("Isolated settings must not be symlinked outside this checkout");
@@ -38,9 +63,10 @@ NodeFS.chmodSync(localHarness, 0o700);
3863
const settings = JSON.parse(NodeFS.readFileSync(settingsPath, "utf8"));
3964
settings.providerInstances ??= {};
4065
settings.providerInstances.antigravity = {
66+
...settings.providerInstances.antigravity,
4167
driver: "antigravity",
4268
enabled: true,
43-
config: { binaryPath: wrapper },
69+
config: { ...settings.providerInstances.antigravity?.config, binaryPath: wrapper },
4470
};
4571
NodeFS.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n");
4672
console.log(`Configured isolated Antigravity fixture. Scenario file: ${scenario}`);

0 commit comments

Comments
 (0)