@decohere/ci-tools 0.0.1-dev.10 → 0.0.1-dev.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { describe, expect, it, vi } from "vitest";
3
+ import { runCreateLauncherSmoke } from "../../src/github/smoke-create-launcher.mjs";
4
+
5
+ const fs = await vi.importActual("node:fs");
6
+ const PUBLISH_YML = fileURLToPath(
7
+ new URL("../../../../.github/workflows/publish.yml", import.meta.url),
8
+ );
9
+
10
+ describe("runCreateLauncherSmoke", () => {
11
+ it("execs npx from a temp directory, not the repo root", () => {
12
+ /** @type {{ cmd: string, args: string[], opts: { cwd?: string } }[]} */
13
+ const calls = [];
14
+ const written = [];
15
+
16
+ const result = runCreateLauncherSmoke({
17
+ createVersion: "0.0.1-dev.80",
18
+ authToken: "tok",
19
+ tmpdir: () => "/tmp",
20
+ mkdtempSync: (prefix) => `${prefix}abc`,
21
+ writeFileSync: (path, body) => {
22
+ written.push({ path, body });
23
+ },
24
+ spawnSync: (cmd, args, opts) => {
25
+ calls.push({ cmd, args, opts });
26
+ return { status: 0 };
27
+ },
28
+ stdio: "pipe",
29
+ });
30
+
31
+ expect(result.workDir).toBe("/tmp/decohere-create-smoke-abc");
32
+ expect(result.workDir).not.toBe(process.cwd());
33
+ expect(calls).toHaveLength(1);
34
+ expect(calls[0].cmd).toBe("npx");
35
+ expect(calls[0].args).toEqual(["--yes", "@decohere/create@0.0.1-dev.80", "--help"]);
36
+ expect(calls[0].opts.cwd).toBe("/tmp/decohere-create-smoke-abc");
37
+ expect(calls[0].opts.cwd).not.toBe(process.cwd());
38
+ expect(written).toEqual([
39
+ {
40
+ path: "/tmp/decohere-create-smoke-abc/.npmrc",
41
+ body: "@decohere:registry=https://registry.npmjs.org/\n//registry.npmjs.org/:_authToken=tok\n",
42
+ },
43
+ ]);
44
+ });
45
+
46
+ it("fails closed without version or token", () => {
47
+ expect(() => runCreateLauncherSmoke({ createVersion: "", authToken: "tok" })).toThrow(
48
+ "CREATE_VERSION is required",
49
+ );
50
+ expect(() =>
51
+ runCreateLauncherSmoke({ createVersion: "0.0.1-dev.80", authToken: "" }),
52
+ ).toThrow("NODE_AUTH_TOKEN is required");
53
+ });
54
+ });
55
+
56
+ describe("publish.yml create smoke + tag", () => {
57
+ const yml = fs.readFileSync(PUBLISH_YML, "utf8");
58
+
59
+ it("wires create smoke through the isolated launcher", () => {
60
+ expect(yml).toContain("node projects/ci-tools/src/github/smoke-create-launcher.mjs");
61
+ expect(yml).toContain("CREATE_VERSION:");
62
+ expect(yml).not.toContain("npx --yes");
63
+ });
64
+
65
+ it("grants the tag job actions:read so publish-prepare can download CI artifacts", () => {
66
+ const tag = yml.slice(yml.indexOf("\n tag:"));
67
+ const perms = tag.slice(tag.indexOf("permissions:"), tag.indexOf("steps:"));
68
+ expect(perms).toMatch(/contents:\s*write/);
69
+ expect(perms).toMatch(/actions:\s*read/);
70
+ });
71
+ });
@@ -1,144 +0,0 @@
1
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
- import { resolve } from "node:path";
3
- import { pathToFileURL } from "node:url";
4
- import { parseLcovByProject } from "../lib/lcov.mjs";
5
-
6
- function parseArgs(argv) {
7
- const options = {
8
- lcov: ".forge/coverage/lcov.info",
9
- thresholds: null,
10
- thresholdsModule: null,
11
- projectsDir: "projects",
12
- };
13
-
14
- for (let index = 0; index < argv.length; index += 1) {
15
- const arg = argv[index];
16
- if (arg === "--lcov") {
17
- options.lcov = argv[index + 1] ?? options.lcov;
18
- index += 1;
19
- continue;
20
- }
21
- if (arg === "--thresholds") {
22
- options.thresholds = argv[index + 1] ?? options.thresholds;
23
- index += 1;
24
- continue;
25
- }
26
- if (arg === "--thresholds-module") {
27
- options.thresholdsModule = argv[index + 1] ?? options.thresholdsModule;
28
- index += 1;
29
- continue;
30
- }
31
- if (arg === "--projectsDir") {
32
- options.projectsDir = argv[index + 1] ?? options.projectsDir;
33
- index += 1;
34
- }
35
- }
36
-
37
- return options;
38
- }
39
-
40
- async function resolveThresholds(options) {
41
- if (options.thresholdsModule) {
42
- const moduleUrl = pathToFileURL(resolve(options.thresholdsModule)).href;
43
- const mod = await import(moduleUrl);
44
- const thresholds = mod.projectCoverageThresholds;
45
- if (typeof thresholds !== "object" || thresholds == null) {
46
- console.error(
47
- `Module ${options.thresholdsModule} must export a 'projectCoverageThresholds' object.`,
48
- );
49
- process.exit(1);
50
- }
51
- return thresholds;
52
- }
53
-
54
- const path = options.thresholds ?? "coverage.config.json";
55
- if (!existsSync(path)) {
56
- console.error(`Thresholds config not found: ${path}`);
57
- process.exit(1);
58
- }
59
- const parsed = JSON.parse(readFileSync(path, "utf8"));
60
- if (typeof parsed !== "object" || parsed == null) {
61
- console.error(
62
- "Thresholds config must be a JSON object mapping project => minimum coverage percentage.",
63
- );
64
- process.exit(1);
65
- }
66
- return parsed;
67
- }
68
-
69
- function formatPct(value) {
70
- return `${value.toFixed(2)}%`;
71
- }
72
-
73
- async function main() {
74
- const options = parseArgs(process.argv.slice(2));
75
- const lcovPath = resolve(options.lcov);
76
- const projectsDirPath = resolve(options.projectsDir);
77
-
78
- if (!existsSync(lcovPath)) {
79
- console.error(`LCOV file not found: ${lcovPath}`);
80
- console.error("Run coverage first (example: npm run test:coverage)");
81
- process.exit(1);
82
- }
83
-
84
- if (!existsSync(projectsDirPath)) {
85
- console.error(`Projects directory not found: ${projectsDirPath}`);
86
- process.exit(1);
87
- }
88
-
89
- const thresholds = await resolveThresholds(options);
90
- const projectDirs = readdirSync(projectsDirPath, { withFileTypes: true })
91
- .filter((entry) => entry.isDirectory())
92
- .map((entry) => entry.name)
93
- .sort((left, right) => left.localeCompare(right));
94
-
95
- const coverageByProject = parseLcovByProject(readFileSync(lcovPath, "utf8"));
96
-
97
- const missingThresholds = projectDirs.filter(
98
- (projectName) => thresholds[projectName] == null,
99
- );
100
- if (missingThresholds.length > 0) {
101
- console.error("Missing coverage thresholds for projects:");
102
- for (const projectName of missingThresholds) console.error(`- ${projectName}`);
103
- console.error(
104
- "Update projectCoverageThresholds in vitest.config.ts to include all project directories.",
105
- );
106
- process.exit(1);
107
- }
108
-
109
- const failures = [];
110
- console.log("Project line coverage thresholds");
111
-
112
- for (const projectName of projectDirs) {
113
- const projectCoverage = coverageByProject.get(projectName) ?? {
114
- totalLines: 0,
115
- coveredLines: 0,
116
- };
117
- const currentPct =
118
- projectCoverage.totalLines === 0
119
- ? 0
120
- : (projectCoverage.coveredLines / projectCoverage.totalLines) * 100;
121
- const minimumPct = Number(thresholds[projectName]);
122
- const passed = Number.isFinite(minimumPct) && currentPct >= minimumPct;
123
-
124
- console.log(
125
- `${passed ? "✅" : "❌"} ${projectName}: ${formatPct(currentPct)} (min ${formatPct(minimumPct)})`,
126
- );
127
-
128
- if (!passed) failures.push({ projectName, currentPct, minimumPct });
129
- }
130
-
131
- if (failures.length > 0) {
132
- console.error("\nCoverage threshold check failed:");
133
- for (const failure of failures) {
134
- console.error(
135
- `- ${failure.projectName}: ${formatPct(failure.currentPct)} is below ${formatPct(failure.minimumPct)}`,
136
- );
137
- }
138
- process.exit(1);
139
- }
140
-
141
- console.log("\nAll project coverage thresholds passed.");
142
- }
143
-
144
- main();
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Clear benchmark history for this publish (workflow_dispatch with clear-history=true)
4
-
5
- import { writeFileSync } from "node:fs";
6
- import { mkdir } from "node:fs/promises";
7
-
8
- const HISTORY_DIR = "projects/ci-tools/dist/ci/bench";
9
- const HISTORY_FILE = `${HISTORY_DIR}/bench-history.json`;
10
-
11
- try {
12
- await mkdir(HISTORY_DIR, { recursive: true });
13
- writeFileSync(
14
- HISTORY_FILE,
15
- JSON.stringify(
16
- {
17
- runs: {},
18
- },
19
- null,
20
- 2,
21
- ),
22
- );
23
- console.log("✓ Cleared benchmark history");
24
- } catch (error) {
25
- console.error("Error clearing benchmark history:", error.message);
26
- process.exit(1);
27
- }