-
Notifications
You must be signed in to change notification settings - Fork 545
Expand file tree
/
Copy pathskeleton.test.ts
More file actions
148 lines (135 loc) · 4.73 KB
/
Copy pathskeleton.test.ts
File metadata and controls
148 lines (135 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { readFile } from "node:fs/promises";
import { describe, expect, test } from "bun:test";
import { CodexSecurity, CodexSecurityError, VERSION } from "../src/index.js";
import type {
Finding,
FindingCodeEvidence,
FindingRootCause,
FindingWriteup,
ScanHardening,
ScanRecord,
} from "../src/index.js";
import { main } from "../src/cli.js";
function capture(): {
stream: Pick<NodeJS.WriteStream, "write">;
text: () => string;
} {
let value = "";
return {
stream: {
write(chunk: string | Uint8Array): boolean {
value += chunk.toString();
return true;
},
},
text: () => value,
};
}
describe("TypeScript package skeleton", () => {
test("advertises the tested Node.js 22, 24, and 26 release lines", async () => {
const packageJson = JSON.parse(
await readFile(new URL("../package.json", import.meta.url), "utf8"),
);
const supportedReleases = ["22.13.0", "22.14.0", "24.0.0", "26.0.0"];
const unsupportedReleases = [
"22.12.0",
"23.0.0",
"23.4.0",
"23.5.0",
"25.0.0",
"27.0.0",
];
expect(
supportedReleases.filter((version) =>
Bun.semver.satisfies(version, packageJson.engines.node),
),
).toEqual(supportedReleases);
expect(
unsupportedReleases.filter((version) =>
Bun.semver.satisfies(version, packageJson.engines.node),
),
).toEqual([]);
});
test("pins each Node.js minimum and preserves protected and latest LTS checks", async () => {
const ciWorkflow = await readFile(
new URL("../../../.github/workflows/node-ci.yml", import.meta.url),
"utf8",
);
expect(ciWorkflow).toContain(
"${{ matrix.node == '22.13.0' && '22' || matrix.node }}",
);
expect(ciWorkflow).toContain('node: ["22.13.0"]');
for (const version of ["24.0.0", "24", "26.0.0", "26"]) {
expect(ciWorkflow).toContain(`node: "${version}"`);
}
});
test("builds packages without a preinstalled package manager and provides a production audit", async () => {
const packageJson = JSON.parse(
await readFile(new URL("../package.json", import.meta.url), "utf8"),
);
expect(packageJson.scripts.build).toBe(
"node --run clean && tsc -p tsconfig.build.json",
);
expect(packageJson.scripts.prepack).toBe("node --run build");
expect(packageJson.scripts["audit:prod"]).toBe(
"pnpm audit --prod --audit-level high",
);
});
test("exposes canonical finding and hardening fields with public types", () => {
const finding = {} as Finding;
const scan = {} as ScanRecord;
const writeup: FindingWriteup | undefined = finding.writeup;
const evidence: FindingCodeEvidence[] | undefined = finding.codeEvidence;
const rootCause: string | FindingRootCause | undefined = finding.rootCause;
const hardening: ScanHardening | undefined = scan.hardening;
const reportPath: string | undefined = finding.writeup?.reportPath;
const firstEvidencePath: string | undefined =
finding.codeEvidence?.[0]?.path;
const portfolioPath: "hardening/hardening.md" | undefined =
scan.hardening?.portfolioPath;
expect([
writeup,
evidence,
rootCause,
hardening,
reportPath,
firstEvidencePath,
portfolioPath,
]).toEqual(new Array(7).fill(undefined));
});
test("exports the async client and curated error base", async () => {
const packageJson = JSON.parse(
await readFile(new URL("../package.json", import.meta.url), "utf8"),
);
const client = new CodexSecurity({ pluginPath: "/tmp/plugin" });
expect(client.config.pluginPath).toBe("/tmp/plugin");
expect(client.metadata).toEqual({
sdk: "@openai/codex-sdk",
sdkVersion: packageJson.dependencies["@openai/codex-sdk"],
executable: "@openai/codex",
executableVersion: packageJson.dependencies["@openai/codex"],
});
expect(new CodexSecurityError("failure").name).toBe("CodexSecurityError");
await client.close();
});
test("provides executable help and version behavior", async () => {
const stdout = capture();
const stderr = capture();
expect(await main([], stdout.stream, stderr.stream)).toBe(0);
expect(stdout.text()).toContain("Usage: codex-security <command>");
expect(stdout.text()).toContain("Integrations:");
expect(stderr.text()).toBe("");
const versionOutput = capture();
expect(await main(["--version"], versionOutput.stream, stderr.stream)).toBe(
0,
);
expect(versionOutput.text()).toBe(`${VERSION}\n`);
const scanHelpOutput = capture();
expect(
await main(["scan", "--help"], scanHelpOutput.stream, stderr.stream),
).toBe(0);
expect(scanHelpOutput.text()).toContain(
"Usage: codex-security scan [repository]",
);
});
});