Skip to content

fix(importer): reject --audit-only with --apply in backfill-specs - #1856

Merged
JOY (JOY) merged 2 commits into
devfrom
fix/1854-backfill-audit-only-guard
Nov 22, 2026
Merged

JOY (JOY) merged 2 commits into
devfrom
fix/1854-backfill-audit-only-guard

Conversation

@JOY

@JOY JOY (JOY) commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1854
Claimant: antigravity:cd885866-827d-4dee-8251-1d84c244e27f

Summary

  • Reject combining --audit-only with --apply (in any flag order) in parseBackfillSpecsArgs with --apply does not combine with --audit-only, preserving the documented read-only contract of --audit-only and preventing unscoped writes across FLAGSHIP_DEVICES_TO_SEED.
  • Extract runBackfillSpecsCli for direct CLI execution with fail-closed validation on auditOnly before invoking runQuickSpecSyncAndAudit({ apply: false, auditOnly: true }).
  • Make runQuickSpecSyncAndAudit strictly read-only: unconditionally reject truthy apply, only, expect, expectInserts, and insertMissing at function entry before loading @supabase/supabase-js or reading environment variables, and remove its legacy unscoped master_products.update(...) loop so delegating callers such as test-ai-enricher.ts --audit-only --apply also fail closed.
  • Add unit tests in apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts covering ['--audit-only', '--apply'], ['--apply', '--audit-only'], combined scoped flags, runBackfillSpecsCli dispatch and parser-bypass guards, and runQuickSpecSyncAndAudit entry checks (with and without auditOnly, plus truthy non-boolean values) alongside valid --audit-only and scoped --apply invocations.

Verification

  • pnpm --filter @repo/crawlers test (pass)
  • pnpm --filter @repo/web test (pass, including core-rate-architecture.test.ts)
  • pnpm typecheck (pass)
  • pnpm lint (pass)
  • pnpm build (pass)
  • pnpm --filter @repo/crawlers test:dist (pass)

Review Gate

  • Local OpenAI Codex CLI (codex@openai-codex) is out of quota until Nov 25, 2026, so Codex review did not run.
  • Fresh-context Reviewer Merge dev into main: Shopee captcha-safe export + duplicate-guard + v1.0.33 #1 (research, CLI logic & tests): Round 1 0 findings (P0-P3); Round 2 (a1528d86) 0 findings (P0-P3).
  • Fresh-context Reviewer Merge pull request #1 from RateBox/dev #2 (research, adversarial data-write safety): Round 1 found 2 P1 (runQuickSpecSyncAndAudit ignoring only/expect or truthy apply when auditOnly omitted, including via test-ai-enricher.ts --audit-only --apply), fixed in a1528d86; Round 2 0 findings (P0-P3).

Fail closed in parseBackfillSpecsArgs, runBackfillSpecsCli, and
runQuickSpecSyncAndAudit when --audit-only is combined with --apply,
preserving the read-only --audit-only contract and preventing unscoped
flagship seed writes.

Refs #1854

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@vercel

vercel Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
rate Ready Ready Preview Nov 22, 2026 10:13am UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The backfill command now rejects incompatible audit-only options, dispatches valid audit-only and backfill runs through a shared CLI function, and uses that function for direct execution.

Changes: Audit-only validation and dispatch

Layer / File(s) Summary
Audit-only option validation
apps/importer/src/shopee/jobs/backfill-specs.ts
The usage text lists options that cannot be combined with --audit-only. The argument parser rejects --apply with --audit-only. The quick-sync/audit entry point rejects incompatible options before creating the Supabase client.
CLI dispatch and execution
apps/importer/src/shopee/jobs/backfill-specs.ts, apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts
The shared dispatcher sends audit-only runs to quick audit with apply disabled, and sends other runs to backfill. Direct execution uses the dispatcher and exits with status 1 when it rejects. Tests cover incompatible flag orders, injected options, valid dispatch paths, and quick-sync/audit validation.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant runBackfillSpecsCli
  participant parseBackfillSpecsArgs
  participant runQuickAudit
  participant runBackfill
  CLI->>runBackfillSpecsCli: argv
  runBackfillSpecsCli->>parseBackfillSpecsArgs: parse argv
  parseBackfillSpecsArgs-->>runBackfillSpecsCli: parsed options
  alt audit-only run
    runBackfillSpecsCli->>runQuickAudit: options with apply false
  else other run
    runBackfillSpecsCli->>runBackfill: parsed options
  end
Loading

Possibly related PRs

  • DOS/Rate#1716: Adds the --only and --expect flags and their mutual-exclusion rule with --audit-only, which this change extends.

Suggested reviewers: dos

Merge Risk: Minimal · up to caf48

The backfill command now fails closed when --audit-only is combined with --apply, so audit runs cannot write. Valid audit-only and scoped-apply invocations are unchanged. Merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: rejecting --audit-only combined with --apply in the backfill-specs importer job. It uses the conventional commits format and matches the summary and linked objecti…
Linked Issues check Passed Issue #1854 coding requirements are met at the reviewed head (caf488e).

- Requirement 3 (parser rejection): parseBackfillSpecsArgs in apps/importer/src/shopee/jobs/backfill-specs.ts now throws `-…
Out of Scope Changes check Passed All changes in backfill-specs.ts connect to #1854 or to the guards the PR describes.

- The parser check, the runQuickSpecSyncAndAudit auditOnly guards and the runBackfillSpecsCli dispatcher i…
Description check Passed The description follows the repository template closely. It has a title-linked closing line (Closes #1854), a Claimant line filled with a real session identifier, a Summary section with what changed a…
Full details: Title check

Explanation

The title names the main change: rejecting --audit-only combined with --apply in the backfill-specs importer job. It uses the conventional commits format and matches the summary and linked objectives. It is 65 characters, which is concise.

Full details: Linked Issues check

Explanation

Issue #1854 coding requirements are met at the reviewed head (caf488e).

  • Requirement 3 (parser rejection): parseBackfillSpecsArgs in apps/importer/src/shopee/jobs/backfill-specs.ts now throws --apply does not combine with --audit-only when auditOnly && apply. The check runs after argument parsing and before any Supabase client is created, so both flag orders are covered. The { auditOnly: true, apply: true } result is no longer returned.
  • Requirement 4 (defensive entry check): runQuickSpecSyncAndAudit takes a new auditOnly option. When it is true, the function throws on apply, only, expect, expectInserts or insertMissing. These checks run before createClient is imported or called. Programmatic runQuickSpecSyncAndAudit({ apply }) still works, so test-ai-enricher.ts keeps its behaviour.
  • CLI dispatch: runBackfillSpecsCli parses argv and routes --audit-only to the quick audit with { apply: false, auditOnly: true }. Other runs go to runMasterSpecsBackfill with unchanged options. Direct execution now uses this dispatcher and exits with status 1 on rejection.
  • Valid invocations: ['--audit-only'] still parses to audit-only. Scoped --apply with --only and --expect is unchanged. Dry-run defaults are unchanged.
  • Tests: apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts imports runBackfillSpecsCli and runQuickSpecSyncAndAudit. The read portion of the file confirms the existing scope tests. The new tests for both flag orders, combined scoped flags, CLI dispatch and fail-closed entry checks were not readable in the returned evidence, because the file read was truncated. Their existence rests on the PR description and the change summary. The pass verdict depends on the implementation evidence above.
Full details: Out of Scope Changes check

Explanation

All changes in backfill-specs.ts connect to #1854 or to the guards the PR describes.

  • The parser check, the runQuickSpecSyncAndAudit auditOnly guards and the runBackfillSpecsCli dispatcher implement issue requirements 3 and 4.
  • The extra auditOnly guards for --only, --expect, --expect-inserts and --insert-missing apply the existing parser rule at the entry points. They are defensive and match the issue's scope.
  • Exporting runBackfillSpecsCli and BackfillSpecsCliRunners lets the tests drive CLI dispatch without running the file as a script. This supports the test requirement.
  • The header doc comment is updated to describe the new mutual exclusions.
  • The refactored direct-execution block keeps the same behaviour for valid invocations. The audit path passes apply: false, which matches the previous apply: args.apply value when apply is false.

No unrelated functional change was found in the reviewed diff.

Full details: Description check

Explanation

The description follows the repository template closely. It has a title-linked closing line (Closes #1854), a Claimant line filled with a real session identifier, a Summary section with what changed and why, and a Verification section listing the commands run with results. The Checklist and Notes sections from the template are absent, so the author did not confirm the checklist items (build, typecheck, lint, tests, docs, and no breaking API changes) in checkbox form, and the description does not state whether the change breaks any API. The Summary covers the behavior change in detail. The Verification section reports build, typecheck, lint, and tests as passing, which partly covers the checklist, but Docs updates and the breaking-API question are not addressed. The Review Gate section is extra but relevant. The description does not include a title line, which the template expects as a Conventional Commit heading. Overall the content is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8bb5ac0e-5efc-4166-8d45-0b608c383db3
Commits

Reviewing files that changed from the base of the PR and between 64bbf72 and caf488e.

Files selected for processing: 2

  • apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts
  • apps/importer/src/shopee/jobs/backfill-specs.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (2 eligible files · 11,538 chars · 1 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 64bbf72 / head caf488e.

✅ CLEAN_PASS: Complete diff reviewed

Reject truthy apply, only, expect, expectInserts, and insertMissing
unconditionally at the entry of runQuickSpecSyncAndAudit and remove its
legacy unscoped master_products update loop so delegating callers such
as test-ai-enricher.ts --audit-only --apply also fail closed.

Refs #1854
dos[bot]
dos Bot approved these changes Nov 22, 2026

@dos dos Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱️ Code Review completed (2 eligible files · 14,294 chars · 3 model call(s) · 1 PR unit(s))

Whole diff with bounded context at base 64bbf72 / head a1528d8.

✅ No verified defects

Some contracts were outside the bounded context, so this verdict rests on the inspected source only.

@JOY

Copy link
Copy Markdown
Contributor Author

PO acceptance: merge at a1528d8

@JOY
JOY (JOY) merged commit 37042d8 into dev Nov 22, 2026
18 checks passed
@JOY
JOY (JOY) deleted the fix/1854-backfill-audit-only-guard branch November 22, 2026 10:24
@JOY JOY (JOY) mentioned this pull request Nov 22, 2026
2 of 6 tasks

This branch was successfully deployed

1 active deployment
Preview — a1528d86 Deployed Nov 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(importer): reject --audit-only combined with --apply in backfill-specs

1 participant