Skip to content

Commit beff7a8

Browse files
committed
test: add bumpPackages tests, wire release tests into CI
- Add tests for bumpPackages: verifies workspace:* protocol is preserved and exact version deps are updated - Add vitest config for scripts/release/ - Add release script test step to test_unit.yml so these run on every PR and push to main
1 parent 04edbd6 commit beff7a8

3 files changed

Lines changed: 153 additions & 35 deletions

File tree

.github/workflows/test_unit.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@ jobs:
7575

7676
- name: Run tests
7777
run: pnpm run test
78+
79+
- name: Run release script tests
80+
run: npx vitest run --config scripts/release/vitest.config.mts

scripts/release/lib/versions.test.ts

Lines changed: 139 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,64 @@
1-
import { describe, it, expect, vi } from "vitest";
1+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2+
import fs from "fs";
3+
import path from "path";
4+
import os from "os";
25
import {
36
parseSemver,
47
computeNextStableVersion,
58
computePrereleaseVersion,
9+
bumpPackages,
610
} from "./versions.js";
711

8-
// Mock loadConfig for computePrereleaseVersion
9-
vi.mock("./config.js", () => ({
10-
ROOT: "/mock",
11-
loadConfig: () => ({
12-
prereleaseTag: "canary",
13-
scopes: {
14-
monorepo: {
15-
packages: [],
16-
versionSource: "@copilotkit/react-core",
17-
sharedVersion: true,
18-
},
19-
cli: { packages: [], versionSource: "copilotkit", sharedVersion: false },
20-
angular: {
21-
packages: [],
22-
versionSource: "@copilotkitnext/angular",
23-
sharedVersion: false,
24-
},
12+
let tmpDir: string;
13+
14+
// Mock config — ROOT points to a temp dir for bumpPackages tests
15+
vi.mock("./config.js", async () => {
16+
return {
17+
get ROOT() {
18+
return tmpDir || "/mock";
2519
},
26-
}),
27-
getScopeConfig: (scope: string) => {
28-
const scopes: Record<string, any> = {
29-
monorepo: {
30-
packages: [],
31-
versionSource: "@copilotkit/react-core",
32-
sharedVersion: true,
33-
},
34-
cli: { packages: [], versionSource: "copilotkit", sharedVersion: false },
35-
angular: {
36-
packages: [],
37-
versionSource: "@copilotkitnext/angular",
38-
sharedVersion: false,
20+
loadConfig: () => ({
21+
prereleaseTag: "canary",
22+
scopes: {
23+
monorepo: {
24+
packages: ["@copilotkit/shared", "@copilotkit/react-core"],
25+
versionSource: "@copilotkit/react-core",
26+
sharedVersion: true,
27+
},
28+
cli: {
29+
packages: ["copilotkit"],
30+
versionSource: "copilotkit",
31+
sharedVersion: false,
32+
},
33+
angular: {
34+
packages: ["@copilotkitnext/angular"],
35+
versionSource: "@copilotkitnext/angular",
36+
sharedVersion: false,
37+
},
3938
},
40-
};
41-
return scopes[scope];
42-
},
43-
}));
39+
}),
40+
getScopeConfig: (scope: string) => {
41+
const scopes: Record<string, any> = {
42+
monorepo: {
43+
packages: ["@copilotkit/shared", "@copilotkit/react-core"],
44+
versionSource: "@copilotkit/react-core",
45+
sharedVersion: true,
46+
},
47+
cli: {
48+
packages: ["copilotkit"],
49+
versionSource: "copilotkit",
50+
sharedVersion: false,
51+
},
52+
angular: {
53+
packages: ["@copilotkitnext/angular"],
54+
versionSource: "@copilotkitnext/angular",
55+
sharedVersion: false,
56+
},
57+
};
58+
return scopes[scope];
59+
},
60+
};
61+
});
4462

4563
describe("parseSemver", () => {
4664
it("parses a stable version", () => {
@@ -134,3 +152,89 @@ describe("computePrereleaseVersion", () => {
134152
);
135153
});
136154
});
155+
156+
describe("bumpPackages", () => {
157+
beforeEach(() => {
158+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "release-test-"));
159+
const packagesDir = path.join(tmpDir, "packages");
160+
161+
// Create shared package
162+
const sharedDir = path.join(packagesDir, "shared");
163+
fs.mkdirSync(sharedDir, { recursive: true });
164+
fs.writeFileSync(
165+
path.join(sharedDir, "package.json"),
166+
JSON.stringify({
167+
name: "@copilotkit/shared",
168+
version: "1.55.2",
169+
}),
170+
);
171+
172+
// Create react-core with workspace:* dep on shared
173+
const reactCoreDir = path.join(packagesDir, "react-core");
174+
fs.mkdirSync(reactCoreDir, { recursive: true });
175+
fs.writeFileSync(
176+
path.join(reactCoreDir, "package.json"),
177+
JSON.stringify({
178+
name: "@copilotkit/react-core",
179+
version: "1.55.2",
180+
dependencies: {
181+
"@copilotkit/shared": "workspace:*",
182+
},
183+
}),
184+
);
185+
});
186+
187+
afterEach(() => {
188+
fs.rmSync(tmpDir, { recursive: true, force: true });
189+
});
190+
191+
it("bumps version fields", () => {
192+
const result = bumpPackages("monorepo", "1.55.3");
193+
expect(result).toHaveLength(2);
194+
expect(result[0].newVersion).toBe("1.55.3");
195+
196+
const pkg = JSON.parse(
197+
fs.readFileSync(
198+
path.join(tmpDir, "packages/shared/package.json"),
199+
"utf8",
200+
),
201+
);
202+
expect(pkg.version).toBe("1.55.3");
203+
});
204+
205+
it("preserves workspace:* protocol in dependencies", () => {
206+
bumpPackages("monorepo", "1.55.3");
207+
208+
const pkg = JSON.parse(
209+
fs.readFileSync(
210+
path.join(tmpDir, "packages/react-core/package.json"),
211+
"utf8",
212+
),
213+
);
214+
expect(pkg.dependencies["@copilotkit/shared"]).toBe("workspace:*");
215+
});
216+
217+
it("updates exact version deps (not workspace protocol)", () => {
218+
// Write react-core with an exact version dep instead of workspace:*
219+
fs.writeFileSync(
220+
path.join(tmpDir, "packages/react-core/package.json"),
221+
JSON.stringify({
222+
name: "@copilotkit/react-core",
223+
version: "1.55.2",
224+
dependencies: {
225+
"@copilotkit/shared": "1.55.2",
226+
},
227+
}),
228+
);
229+
230+
bumpPackages("monorepo", "1.55.3");
231+
232+
const pkg = JSON.parse(
233+
fs.readFileSync(
234+
path.join(tmpDir, "packages/react-core/package.json"),
235+
"utf8",
236+
),
237+
);
238+
expect(pkg.dependencies["@copilotkit/shared"]).toBe("1.55.3");
239+
});
240+
});

scripts/release/vitest.config.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
environment: "node",
6+
globals: true,
7+
include: ["lib/**/*.{test,spec}.ts"],
8+
reporters: [["default", { summary: false }]],
9+
silent: true,
10+
},
11+
});

0 commit comments

Comments
 (0)