GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — OpenAgentPack/scripts/audit.test.ts at main · modelstudioai/OpenAgentPack

Expand file tree

/

audit.test.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
125 lines (114 loc) · 5.18 KB
/

audit.test.ts

Copy path

File metadata and controls

125 lines (114 loc) · 5.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import { describe, expect, test } from "bun:test";
import { readFileSync } from "node:fs";
import { type AuditResult, isTransientAuditFailure, runAudit } from "./audit.ts";
import { profileSteps } from "./verify.ts";
const connectionClosed: AuditResult = {
exitCode: 1,
stdout: "",
stderr: "bun audit v1.3.5 (1e86cebd)\nConnectionClosed: audit request failed\n",
};
const success: AuditResult = { exitCode: 0, stdout: "No vulnerabilities found\n", stderr: "" };
function auditSequence(results: AuditResult[]) {
const invocations: (readonly string[])[] = [];
const delays: number[] = [];
const stdout: string[] = [];
const stderr: string[] = [];
return {
get attempts() {
return invocations.length;
},
invocations,
delays,
stdout,
stderr,
dependencies: {
execute: (args: readonly string[]) => {
const result = results[invocations.length];
invocations.push(args);
if (!result) throw new Error("Unexpected audit attempt");
return result;
},
sleep: async (delayMs: number) => {
delays.push(delayMs);
},
writeStdout: (output: string) => stdout.push(output),
writeStderr: (output: string) => stderr.push(output),
},
};
}
describe("dependency audit", () => {
test("audits production before applying the single exception in the full audit", async () => {
const sequence = auditSequence([success, success]);
expect(await runAudit(sequence.dependencies)).toBe(0);
expect(sequence.invocations).toEqual([["--prod"], ["--ignore", "GHSA-fc5q-39xc-vjpf"]]);
expect(sequence.delays).toEqual([]);
});
test("retries the CI ConnectionClosed error in the full audit with bounded backoff", async () => {
const sequence = auditSequence([success, connectionClosed, connectionClosed, success]);
expect(await runAudit(sequence.dependencies)).toBe(0);
expect(sequence.attempts).toBe(4);
expect(sequence.delays).toEqual([2_000, 5_000]);
expect(sequence.stderr.join("")).toContain(connectionClosed.stderr);
expect(sequence.stderr.join("")).toContain("retrying (3/3)");
});
test("still fails after three unsuccessful network attempts", async () => {
const sequence = auditSequence([connectionClosed, connectionClosed, connectionClosed]);
expect(await runAudit(sequence.dependencies)).toBe(1);
expect(sequence.attempts).toBe(3);
expect(sequence.delays).toEqual([2_000, 5_000]);
expect(sequence.stderr.join("")).toContain("verification remains failed");
});
test("blocks the excepted advisory in production, even after a transient error", async () => {
const finding = { exitCode: 1, stdout: "GHSA-fc5q-39xc-vjpf\n1 vulnerability (1 high)\n", stderr: "" };
const sequence = auditSequence([connectionClosed, finding]);
expect(await runAudit(sequence.dependencies)).toBe(1);
expect(sequence.invocations).toEqual([["--prod"], ["--prod"]]);
expect(sequence.delays).toEqual([2_000]);
expect(sequence.stdout).toContain(finding.stdout);
});
test("blocks other findings in the full audit", async () => {
const finding = { exitCode: 1, stdout: "1 vulnerability (1 high)\n", stderr: "" };
const sequence = auditSequence([success, finding]);
expect(await runAudit(sequence.dependencies)).toBe(1);
expect(sequence.attempts).toBe(2);
expect(sequence.delays).toEqual([]);
expect(sequence.stdout).toContain(finding.stdout);
});
test("does not retry unknown errors, auth failures, invalid lockfiles, or interrupted processes", async () => {
for (const result of [
{ exitCode: 2, stdout: "", stderr: "error: invalid lockfile\n" },
{ exitCode: 1, stdout: "", stderr: "HTTP 401 Unauthorized\n" },
{ exitCode: 1, stdout: "", stderr: "unknown audit error\n" },
{ ...connectionClosed, errorCode: "ENOENT" },
{ ...connectionClosed, signal: "SIGINT" },
]) {
const sequence = auditSequence([result]);
expect(await runAudit(sequence.dependencies)).toBe(result.exitCode);
expect(sequence.attempts).toBe(1);
expect(sequence.delays).toEqual([]);
}
});
test("handles ANSI banners but does not match errors embedded in vulnerability reports", () => {
expect(isTransientAuditFailure({ ...connectionClosed, stderr: `\x1b[1m${connectionClosed.stderr}\x1b[0m` })).toBe(
true,
);
expect(isTransientAuditFailure({ ...connectionClosed, stdout: "1 vulnerability (1 high)\n" })).toBe(false);
expect(
isTransientAuditFailure({ ...connectionClosed, stderr: "high: ConnectionClosed: audit request failed\n" }),
).toBe(false);
});
test("bounds retries of timed-out audit processes", async () => {
const timeout = { exitCode: 1, stdout: "", stderr: "", errorCode: "ETIMEDOUT", signal: "SIGTERM" };
const sequence = auditSequence([timeout, timeout, timeout]);
expect(await runAudit(sequence.dependencies)).toBe(1);
expect(sequence.attempts).toBe(3);
expect(sequence.stderr.join("")).toContain("ETIMEDOUT");
expect(isTransientAuditFailure({ ...timeout, stdout: "1 vulnerability (1 high)\n" })).toBe(false);
});
test("routes both full and release verification through the audit wrapper", () => {
const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
expect(manifest.scripts.audit).toBe("bun scripts/audit.ts");
expect(profileSteps("full")).toContain("audit");
expect(profileSteps("release")).toContain("audit");
});
});
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.