Skip to content

test(core): harden the rule suite with realistic negative cases#18

Open
PunGrumpy wants to merge 5 commits into
advisor/004-shared-image-ref-parserfrom
advisor/006-realistic-negative-test-cases
Open

test(core): harden the rule suite with realistic negative cases#18
PunGrumpy wants to merge 5 commits into
advisor/004-shared-image-ref-parserfrom
advisor/006-realistic-negative-test-cases

Conversation

@PunGrumpy

Copy link
Copy Markdown
Owner

What

Hardens the rule suite with realistic negative cases across all 25 rules, so the next rule-specificity bug is caught by CI instead of by an audit. Test-only — no source changes, no changeset. Implements plan 006. Depends on 003 and 004.

Why

The suite was not assertion-free, but every negative case tested the trivially-compliant form (USER node, FROM node:22.2.0-alpine, ENV NORMAL_VAR). Meanwhile every bug fixed in plans 003/004 lived in a realistic shape the suite never constructed: multi-stage builds, --chown flags, registry ports, digest pins, stage aliases, ARG-driven bases. This closes that gap systematically.

What changed (all in packages/core/test/rules.test.ts, purely additive — 0 deletions)

  • A realistic-compliance negative on every one of the 25 canonical per-rule blocks — e.g. use-multi-stage on a real 2-stage build, clean-package-cache on apk add --no-cache, require-labels on OCI labels, use-dockerignore on COPY --chown . ., compose rules on deploy-block configs, order-layers on manifest→install→source ordering.
  • "Still fires" guards against over-correction from 003/004: no-root-user on a multi-stage file whose final stage lacks USER; no-secrets-in-env on AWS_SECRET_ACCESS_KEY and API_KEY (fake placeholder values); pin-image-version on registry.example.com:5000/team/app (untagged behind a port); no-add-remote on ADD --chown … https://….
  • Two known false positives documented as test.todo (not fixed — out of scope, no approved plan): use-pipefail flags a regex alternation inside a quoted argument (RUN grep -E "foo|bar" …), and avoid-run-cd matches cd inside path segments/strings (/opt/cd, abcd). Both have the same root cause — matching raw text with no shell-quote awareness — and would likely be fixed together by a small tokenizer pre-pass. Mirrored in plans/README.md's deferred list.

Two ${VAR} negatives (ENV API_KEY=${API_KEY} → silent, WORKDIR ${APP_HOME} → silent) assert intended behavior — both rules have explicit variable-skipping guards in source (!value.startsWith("$") and \$ in the absolute-path regex), so these document the contract rather than cementing a false negative.

Verification

  • core: 47 pass / 2 todo / 0 fail · cli: 12/0 · typecheck 0 · ultracite check 0.
  • Coverage of src/rules/: security.ts 99.5→100%, compose.ts 99.3→100%, performance.ts 91.6→93.7%.
  • No bug beyond the two documented false positives was found; no assertion was weakened.

Stacking

Base is advisor/004-shared-image-ref-parser (PR #16), which stacks on 003→002. Sibling of PR #17 (005). GitHub auto-retargets to main once #14#16 merge. Merge after #14, #15, #16.

🤖 Generated with Claude Code

Extend the no-root-user, no-secrets-in-env, and no-add-remote rule
tests with realistic compliant shapes (multi-stage final USER, ARG
build-secret passthrough, multiple ENV vars, local archive ADD with
--chown) and confirm genuine secret-shaped keys (AWS_SECRET_ACCESS_KEY,
API_KEY) still trigger a diagnostic.
Extend no-version-key, require-resource-limits, require-restart-policy,
and use-depends-on-condition with realistic multi-service compliant
compose shapes (deploy.resources.limits, deploy.restart_policy, and
long-form depends_on with a service_healthy condition).
Extend clean-package-cache with an apk-based realistic compliant
shape (apk add --no-cache) to cover the non-apt package manager path.
prefer-slim-base and avoid-dev-dependencies already carry realistic
compliant coverage from plans 003/004.
Extend absolute-workdir, require-healthcheck, prefer-copy-over-add,
use-exec-form, and require-labels with realistic compliant shapes
(variable WORKDIR, multi-stage HEALTHCHECK, flagged archive ADD,
ENTRYPOINT exec form, OCI label keys).

Document the two known rule-specificity false positives as
test.todo (not fixed): use-pipefail flags a quoted regex alternation
as an unguarded pipe, and avoid-run-cd matches 'cd' inside unrelated
path segments/words via an unbounded \bcd\b match against inst.args.
@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docker-doctor Skipped Skipped Jul 23, 2026 2:40am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant