Skip to content

Commit f1039e1

Browse files
fix(blocks): sync-blocks takes its directory from src/base-dir.ts
sync-blocks worked out the repository's directory for itself, the one module that still did. It would have worked in the repository while every other module worked in a test's temporary directory. tests/base-dir.test.ts names the line. The blocks tests import the engine sandbox first, as every engine test file does. The test that runs sync-blocks --apply gives that one call 240 seconds. It starts four commands in a row and took 72 seconds on a slow machine beside the rest of the suite. cliRun takes the limit as a parameter and keeps 60 seconds for every other call. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent 3f70a3f commit f1039e1

7 files changed

Lines changed: 14 additions & 5 deletions

‎src/sync-blocks-cmd.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { spawnSync } from "node:child_process";
1515
import { existsSync, readdirSync, statSync } from "node:fs";
1616
import { join, relative, resolve } from "node:path";
1717
import { fileURLToPath } from "node:url";
18+
import { baseDir } from "./base-dir.ts";
1819
import { blocksChanged, blocksRecordRead } from "./blocks.ts";
1920
import { FOLDER_MAP, orgResourcesRead } from "./resource-parse.ts";
2021

@@ -96,10 +97,7 @@ export async function syncBlocksRun(
9697
): Promise<number> {
9798
const rootDir =
9899
overrides.rootDir ??
99-
resolve(
100-
process.env.VAPI_GITOPS_ROOT ??
101-
fileURLToPath(new URL("..", import.meta.url)),
102-
);
100+
resolve(process.env.VAPI_GITOPS_ROOT ?? baseDir());
103101
const deploy =
104102
overrides.applyRun ??
105103
((org: string, paths: string[]) => applyRun(rootDir, org, paths));

‎tests/blocks-helpers.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export function cliRun(
167167
script: string,
168168
args: string[],
169169
port: number,
170+
// One command's worth. A call that starts further commands passes more.
171+
timeoutMs = 60_000,
170172
): { code: number | null; output: string } {
171173
const result = spawnSync(
172174
process.execPath,
@@ -179,7 +181,7 @@ export function cliRun(
179181
VAPI_BASE_URL: `http://127.0.0.1:${port}`,
180182
},
181183
encoding: "utf8",
182-
timeout: 60_000,
184+
timeout: timeoutMs,
183185
},
184186
);
185187
return { code: result.status, output: `${result.stdout}\n${result.stderr}` };

‎tests/blocks-promotion.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./engine-sandbox.ts";
12
import assert from "node:assert/strict";
23
import { execFileSync } from "node:child_process";
34
import { mkdtempSync, readFileSync, rmSync } from "node:fs";

‎tests/blocks-pull.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./engine-sandbox.ts";
12
import assert from "node:assert/strict";
23
import { existsSync, readdirSync, readFileSync, rmSync } from "node:fs";
34
import { join } from "node:path";

‎tests/blocks-sync.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./engine-sandbox.ts";
12
import assert from "node:assert/strict";
23
import { readFileSync, rmSync } from "node:fs";
34
import { join } from "node:path";
@@ -266,6 +267,10 @@ test("--apply pushes through the drift check: an untouched resource is updated,
266267
"src/sync-blocks-cmd.ts",
267268
["--org", ORG, "--apply"],
268269
stub.port,
270+
// sync-blocks starts apply, which starts a pull and a push: four
271+
// commands' start-up in one call, on a machine running the rest of
272+
// the suite beside it.
273+
240_000,
269274
);
270275
const patched = (await stub.requests()).filter((request) =>
271276
request.startsWith("PATCH /assistant/"),

‎tests/blocks-validate.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./engine-sandbox.ts";
12
import assert from "node:assert/strict";
23
import test from "node:test";
34

‎tests/blocks.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./engine-sandbox.ts";
12
import assert from "node:assert/strict";
23
import { existsSync, readFileSync, rmSync } from "node:fs";
34
import { join } from "node:path";

0 commit comments

Comments
 (0)