You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(importer): reject --audit-only with --apply in backfill-specs - #1856
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.
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
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.
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.
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.
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: 4
Check name
Status
Explanation
Title check
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
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
All changes in backfill-specs.ts connect to #1854 or to the guards the PR describes.
- The parser check, the runQuickSpecSyncAndAuditauditOnly guards and the runBackfillSpecsCli dispatcher i…
Description check
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 runQuickSpecSyncAndAuditauditOnly 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.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1854
Claimant: antigravity:cd885866-827d-4dee-8251-1d84c244e27f
Summary
--audit-onlywith--apply(in any flag order) inparseBackfillSpecsArgswith--apply does not combine with --audit-only, preserving the documented read-only contract of--audit-onlyand preventing unscoped writes acrossFLAGSHIP_DEVICES_TO_SEED.runBackfillSpecsClifor direct CLI execution with fail-closed validation onauditOnlybefore invokingrunQuickSpecSyncAndAudit({ apply: false, auditOnly: true }).runQuickSpecSyncAndAuditstrictly read-only: unconditionally reject truthyapply,only,expect,expectInserts, andinsertMissingat function entry before loading@supabase/supabase-jsor reading environment variables, and remove its legacy unscopedmaster_products.update(...)loop so delegating callers such astest-ai-enricher.ts --audit-only --applyalso fail closed.apps/importer/src/shopee/__tests__/backfill-specs-scope.test.tscovering['--audit-only', '--apply'],['--apply', '--audit-only'], combined scoped flags,runBackfillSpecsClidispatch and parser-bypass guards, andrunQuickSpecSyncAndAuditentry checks (with and withoutauditOnly, plus truthy non-boolean values) alongside valid--audit-onlyand scoped--applyinvocations.Verification
pnpm --filter @repo/crawlers test(pass)pnpm --filter @repo/web test(pass, includingcore-rate-architecture.test.ts)pnpm typecheck(pass)pnpm lint(pass)pnpm build(pass)pnpm --filter @repo/crawlers test:dist(pass)Review Gate
codex@openai-codex) is out of quota until Nov 25, 2026, so Codex review did not run.research, CLI logic & tests): Round 10 findings (P0-P3); Round 2 (a1528d86)0 findings (P0-P3).research, adversarial data-write safety): Round 1 found2 P1(runQuickSpecSyncAndAuditignoringonly/expector truthyapplywhenauditOnlyomitted, including viatest-ai-enricher.ts --audit-only --apply), fixed ina1528d86; Round 20 findings (P0-P3).