Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Run the core image's production npm audit in CI (#2114)

Regan Bella42ecbb0c2f7
diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml
index 9bc6577dc..7282c9f2b 100644
--- a/.github/workflows/cicd.yml
+++ b/.github/workflows/cicd.yml
@@ -208,6 +208,21 @@ jobs:
echo "use the contributor's real email, or drop the trailer." >&2
exit 1
+ dependency-audit:
+ name: Production dependency audit
+ timeout-minutes: 5
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
+ with:
+ persist-credentials: false
+ - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444
+ with:
+ node-version-file: .node-version
+ # Same gate the core image build runs. Never reused: advisories appear after a tree is tested.
+ - name: Audit production dependencies
+ run: npm run audit:prod
+
lint:
name: Lint
needs: reuse
@@ -466,7 +481,7 @@ jobs:
timeout-minutes: 3
continue-on-error: true
if: always() && !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/main'
- needs: [core, cli, lint, core-postgres, admin-plugin, web-ui-plugin, auth-plugin, portal-plugin]
+ needs: [core, cli, lint, dependency-audit, core-postgres, admin-plugin, web-ui-plugin, auth-plugin, portal-plugin]
runs-on: ubuntu-latest
permissions: {}
steps:
diff --git a/deploy/core/Dockerfile b/deploy/core/Dockerfile
index 4f879fc29..8aea36765 100644
--- a/deploy/core/Dockerfile
+++ b/deploy/core/Dockerfile
@@ -19,7 +19,7 @@ WORKDIR /app
COPY package.json package-lock.json ./
COPY .husky/install.mjs .husky/install.mjs
-RUN npm ci --omit=dev && npm audit --omit=dev --audit-level=moderate \
+RUN npm ci --omit=dev && npm run audit:prod \
&& rm -rf /root/.npm /tmp/node-compile-cache
COPY --from=connector-sdk-build /app/.generated/connector-sdk ./.generated/connector-sdk
diff --git a/package.json b/package.json
index 1981ac7c4..71ef63db1 100644
--- a/package.json
+++ b/package.json
@@ -58,6 +58,7 @@
"lint:ox": "oxlint --deny-warnings src plugins scripts cli test",
"dev-instance:doctor": "bash scripts/dev-instance.sh doctor",
"lint:knip": "knip",
+ "audit:prod": "npm audit --omit=dev --audit-level=moderate",
"migrate:transcript-tape": "node scripts/migrate-transcript-tape.ts",
"build:app-annotations": "node scripts/build-app-devbar.mjs"
},
diff --git a/scripts/reuse-ci.ts b/scripts/reuse-ci.ts
index 874a97c6f..cc013dc40 100644
--- a/scripts/reuse-ci.ts
+++ b/scripts/reuse-ci.ts
@@ -8,6 +8,7 @@ export const CI_JOBS = [
"Core",
"CLI",
"Lint",
+ "Production dependency audit",
"Core Postgres tests",
"Admin plugin",
"Web UI plugin",
diff --git a/test/ci-reuse.test.ts b/test/ci-reuse.test.ts
index afe1fe0ce..4e71d8a2c 100644
--- a/test/ci-reuse.test.ts
+++ b/test/ci-reuse.test.ts
@@ -299,7 +299,7 @@ test("all quality jobs keep successful names and missing proof runs full checks"
const name = block.match(/^ {4}name: (.+)$/m)![1]!;
if (id === "core-tests") names.push(...[1, 2, 3, 4, 5].map((n) => name.replace("${{ matrix.shard }}", String(n))));
else names.push(name);
- if (["core", "coauthor-trailers"].includes(id)) continue;
+ if (["core", "coauthor-trailers", "dependency-audit"].includes(id)) continue;
assert.ok(block.includes("needs: reuse\n if: always() && !cancelled()"));
const steps = block.split(/(?=^ {6}- (?:name|uses):)/m).slice(1);
assert.ok(steps[0]!.includes("if: needs.reuse.outputs.reusable == 'true'"));
@@ -317,7 +317,9 @@ test("deployment notice fires only for a fully green main push and holds no repo
job.includes("if: always() && !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/main'"),
);
assert.ok(
- job.includes("needs: [core, cli, lint, core-postgres, admin-plugin, web-ui-plugin, auth-plugin, portal-plugin]"),
+ job.includes(
+ "needs: [core, cli, lint, dependency-audit, core-postgres, admin-plugin, web-ui-plugin, auth-plugin, portal-plugin]",
+ ),
);
assert.ok(job.includes("permissions: {}"));
assert.ok(job.includes("continue-on-error: true"));
diff --git a/test/deploy-core-image.test.ts b/test/deploy-core-image.test.ts
index 809b286b4..9ec1eaad2 100644
--- a/test/deploy-core-image.test.ts
+++ b/test/deploy-core-image.test.ts
@@ -16,9 +16,15 @@ test("core deploy image includes git", () => {
);
assert.match(
dockerfile,
- /npm audit --omit=dev --audit-level=moderate/,
- "the production dependency threshold is a build gate",
+ /npm ci --omit=dev && npm run audit:prod/,
+ "the production dependency audit is a build gate",
);
+ const packageJson = JSON.parse(readFileSync(join(repoRoot, "package.json"), "utf8")) as {
+ scripts: Record<string, string>;
+ };
+ assert.equal(packageJson.scripts["audit:prod"], "npm audit --omit=dev --audit-level=moderate");
+ const workflow = readFileSync(join(repoRoot, ".github/workflows/cicd.yml"), "utf8");
+ assert.match(workflow, /run: npm run audit:prod/, "CI runs the same audit as the core image build");
assert.doesNotMatch(dockerfile, /patch-pi-shrinkwrap/, "the dependency layer should be lockfile-only");
assert.match(
dockerfile,