Skip to content

Commit f09aad2

Browse files
test: ask for the sandbox import only in CI for the engine's own repository
The check that every test file imports tests/engine-sandbox.ts first was also asked on a person's machine, wherever origin pointed at VapiAI/gitops. A repository cloned straight from the engine's keeps that origin, so a test of its owner's under tests/ made one engine test fail in npm test. Before the sandbox existed it passed. The check is now asked only where GITHUB_REPOSITORY is VapiAI/gitops, which is CI for the engine's own repository. A contributor who leaves the import out finds out on the pull request. GITHUB_REPOSITORY=VapiAI/gitops npm test asks it on a machine. Tests and docs only. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent f7ff5a8 commit f09aad2

5 files changed

Lines changed: 46 additions & 47 deletions

File tree

‎AGENTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ For changes under `src/`, `tests/` or `.github/`:
331331
makes the engine work in a temporary directory and stops the test changing
332332
files in the repository. A test of your own, for your own repository,
333333
leaves it out and works in the repository as before. The suite asks for
334-
the import only where `origin` is `VapiAI/gitops` itself.
334+
the import only in CI for `VapiAI/gitops` itself, so a clone on your
335+
machine is never asked.
335336
- A test that starts a test runner of its own goes in `tests/repository/`
336337
and runs with `npm run test:repository`, not with `npm test`.
337338
- Changing a command's flags or behaviour? Update

‎CONTRIBUTING.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ learnings are all welcome.
2828
`node:test` and live in `tests/`; they never call the real Vapi API.
2929
Start every new test file with `import "./engine-sandbox.ts";`, before
3030
any other import. It gives the engine a temporary directory to work in
31-
and stops the test changing files in the repository. `npm test` fails
32-
here when a test file is missing it.
31+
and stops the test changing files in the repository. CI on your pull
32+
request fails when a test file is missing it; `npm test` on your machine
33+
doesn't ask, so that a test of your own in a clone is left alone. To ask
34+
locally, run `GITHUB_REPOSITORY=VapiAI/gitops npm test`.
3335
4. Run `npm run build` and `npm test` again, then open a pull request.
3436
If you changed a test, or code that writes or removes files, also run
3537
`npm run test:repository`. It runs the suite inside copies of a

‎improvements.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,9 @@ module takes the engine's directory from `src/base-dir.ts`
21502150
engine test file imports `tests/engine-sandbox.ts` first, which points the
21512151
engine at a temporary directory and makes every `node:fs` change inside the
21522152
repository throw, so the protection holds however the file is started. In
2153-
the engine's own repository a test file without that import fails the suite.
2153+
CI for the engine's own repository a test file without that import fails the
2154+
suite; on a person's machine that check is skipped, so a clone that holds a
2155+
test of its owner's behaves as it did before.
21542156
`tests/repository/suite-leaves-the-repository.test.ts` runs the engine's
21552157
whole suite inside a copy of a customer-shaped repository in each layout and
21562158
compares every file, tracked, untracked and ignored, before and after. It

‎tests/engine-sandbox.test.ts‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./engine-sandbox.ts";
22
import assert from "node:assert/strict";
3-
import { execFileSync, spawnSync } from "node:child_process";
3+
import { spawnSync } from "node:child_process";
44
import {
55
cpSync,
66
mkdirSync,
@@ -135,28 +135,18 @@ test("an engine test started by hand, without the preload npm test adds, still w
135135
);
136136
});
137137

138-
// Whether this is the engine's own repository: on a runner by its name, on a
139-
// person's machine by where origin points, over https or ssh. Anywhere else a
140-
// test file without the import is that repository's own test.
141-
function engineRepository(): boolean {
142-
const named = process.env.GITHUB_REPOSITORY;
143-
if (named) return named.toLowerCase() === "vapiai/gitops";
144-
try {
145-
const origin = execFileSync(
146-
"git",
147-
["config", "--get", "remote.origin.url"],
148-
{ cwd: REPO, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] },
149-
).trim();
150-
return /[/:]vapiai\/gitops(\.git)?\/?$/i.test(origin);
151-
} catch {
152-
return false;
153-
}
138+
// Whether this is CI for the engine's own repository, by the name GitHub
139+
// gives the runner. Anywhere else, a person's machine included, a test file
140+
// without the import is that repository's own test, whatever origin says: a
141+
// repository cloned straight from the engine's keeps its origin.
142+
function engineRepositoryCi(): boolean {
143+
return process.env.GITHUB_REPOSITORY?.toLowerCase() === "vapiai/gitops";
154144
}
155145

156-
test("in the engine's own repository, every test file imports the sandbox first", {
157-
skip: engineRepository()
146+
test("in CI for the engine's own repository, every test file imports the sandbox first", {
147+
skip: engineRepositoryCi()
158148
? false
159-
: "not the engine's own repository: a test file without the import is this repository's own",
149+
: "not CI for the engine's own repository: a test file without the import is this repository's own",
160150
}, () => {
161151
const other = [
162152
...testFiles(join(REPO, "tests")).other,
@@ -167,7 +157,7 @@ test("in the engine's own repository, every test file imports the sandbox first"
167157
assert.deepEqual(
168158
other,
169159
[],
170-
`Every engine test file starts with ${SANDBOX} (${SANDBOX_FROM_FOLDER} under tests/repository/) and these don't: ${other.join(", ")}. This is asked because origin is VapiAI/gitops; in a repository of your own, with its own origin, a test of your own is left alone.`,
160+
`Every engine test file starts with ${SANDBOX} (${SANDBOX_FROM_FOLDER} under tests/repository/) and these don't: ${other.join(", ")}. This is asked because GITHUB_REPOSITORY is VapiAI/gitops; anywhere else a test file without the import is left alone.`,
171161
);
172162
});
173163

‎tests/repository/import-check.test.ts‎

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import test from "node:test";
1515
import { fileURLToPath } from "node:url";
1616

1717
// tests/engine-sandbox.test.ts fails when a test file doesn't import the
18-
// sandbox first, in the engine's own repository and in no other: anywhere
19-
// else such a file is that repository's own test. Each case below asks that
20-
// check in a small repository that holds one test file without the import,
21-
// named each way a repository can be.
18+
// sandbox first, in CI for the engine's own repository and nowhere else:
19+
// anywhere else such a file is that repository's own test. That includes a
20+
// person's clone of the engine's repository, which keeps its origin and may
21+
// hold a test of its owner's. Each case below asks that check in a small
22+
// repository that holds one test file without the import, named each way a
23+
// repository can be.
2224

2325
const REPO = fileURLToPath(new URL("../..", import.meta.url));
2426

@@ -78,48 +80,50 @@ function importCheckIn(named: { runner?: string; origin?: string }): string {
7880
}
7981
}
8082

81-
test("the import check is asked in the engine's own repository, however it is named, and in no other", () => {
83+
test("the import check is asked in CI for the engine's own repository, and nowhere else", () => {
8284
const fork = "acme/voice-agents";
8385
assert.deepEqual(
8486
{
8587
"a runner in the engine's repository": importCheckIn({
8688
runner: "VapiAI/gitops",
8789
origin: "https://github.com/VapiAI/gitops",
8890
}),
89-
"a clone over https": importCheckIn({
91+
"a runner in the engine's repository, named in lower case": importCheckIn(
92+
{ runner: "vapiai/gitops", origin: "https://github.com/vapiai/gitops" },
93+
),
94+
"a clone of the engine's repository over https": importCheckIn({
9095
origin: "https://github.com/VapiAI/gitops.git",
9196
}),
92-
"a clone over https, typed in lower case and without .git": importCheckIn(
93-
{ origin: "https://github.com/vapiai/gitops" },
94-
),
95-
"a clone over ssh": importCheckIn({
97+
"a clone of the engine's repository over ssh": importCheckIn({
9698
origin: "git@github.com:VapiAI/gitops.git",
9799
}),
98100
"a runner in a fork": importCheckIn({
99101
runner: fork,
100102
origin: `https://github.com/${fork}`,
101103
}),
102-
"a clone of a fork over https": importCheckIn({
103-
origin: `https://github.com/${fork}.git`,
104-
}),
105-
"a clone of a fork over ssh": importCheckIn({
106-
origin: `git@github.com:${fork}.git`,
104+
"a runner in a repository that kept the engine's origin": importCheckIn({
105+
runner: fork,
106+
origin: "https://github.com/VapiAI/gitops.git",
107107
}),
108-
"a fork that kept the name": importCheckIn({
108+
"a runner in a fork that kept the name": importCheckIn({
109+
runner: "acme/gitops",
109110
origin: "https://github.com/acme/gitops.git",
110111
}),
112+
"a clone of a fork": importCheckIn({
113+
origin: `git@github.com:${fork}.git`,
114+
}),
111115
"a repository with no origin": importCheckIn({}),
112116
},
113117
{
114118
"a runner in the engine's repository": "own.test.ts lacks the import",
115-
"a clone over https": "own.test.ts lacks the import",
116-
"a clone over https, typed in lower case and without .git":
119+
"a runner in the engine's repository, named in lower case":
117120
"own.test.ts lacks the import",
118-
"a clone over ssh": "own.test.ts lacks the import",
121+
"a clone of the engine's repository over https": "not asked",
122+
"a clone of the engine's repository over ssh": "not asked",
119123
"a runner in a fork": "not asked",
120-
"a clone of a fork over https": "not asked",
121-
"a clone of a fork over ssh": "not asked",
122-
"a fork that kept the name": "not asked",
124+
"a runner in a repository that kept the engine's origin": "not asked",
125+
"a runner in a fork that kept the name": "not asked",
126+
"a clone of a fork": "not asked",
123127
"a repository with no origin": "not asked",
124128
},
125129
);

0 commit comments

Comments
 (0)