Skip to content

fix: add diff -fail-on gate and report added prompts as new - #7

Merged
sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/3-diff-exit-code
Oct 18, 2026
Merged

sujal-maheshwari2004 merged 1 commit into
mainfrom
fix/3-diff-exit-code

Conversation

@sujal-maheshwari2004

Copy link
Copy Markdown
Contributor

What was wrong

  • promptctl diff always exited 0, so CI had to grep the output for => structural to gate a change.
  • A prompt added since the ref was diffed against an empty file and reported as structural instead of new.

The fix

  • New flag -fail-on (also --fail-on): a comma-separated list of verdicts (new, structural, tweak, minor). diff still prints the full diff, then exits 1 if any prompt's verdict is in the list and names the matching prompts on stderr. Without the flag the exit code stays 0 (backward compatible). An unknown verdict name exits 2, like other flag errors.
  • A prompt that isn't in the ref now prints new prompt (not in <ref>) / => new instead of a fake insert hunk that always reads structural.
  • Flags can come before or after the ref (promptctl diff origin/main -fail-on structural).
  • The diff loop moved into runDiff, which returns each prompt's verdict (semdiff.Worst of its hunks), so it can be tested in-process.

Tests

New cmd/promptctl/diff_test.go: TestRunDiffVerdicts (real go-git repo: a rewrite reads structural, an added prompt reads new), TestRunDiffNoChanges, and TestParseFailOn.

With the new branch disabled, the test fails as on main:

--- FAIL: TestRunDiffVerdicts (0.26s)
    diff_test.go:62: runDiff = [{acme/support/added.prompt structural} {acme/support/agent.prompt structural}], want [{acme/support/added.prompt new} {acme/support/agent.prompt structural}]

Full suite: GOWORK=off go build ./... && go vet ./... && go test ./... → ok github.com/priompt/cli/cmd/promptctl

Before / after (real run, offline lexical embedder)

Repo with one committed prompt rewritten and one new prompt.

Before (main):

## acme/support/new.prompt
change @ new lines 1-1 (old 1-0): insert
  Signal 2 (point delta): 1.000
  ...
  => structural
exit=0
$ promptctl diff -fail-on structural
unknown ref "-fail-on": reference not found
exit=1

After:

## acme/support/agent.prompt
...
  => structural

## acme/support/new.prompt
new prompt (not in HEAD)
  => new

exit=0
$ promptctl diff -fail-on structural
diff: 1 prompt(s) match -fail-on structural: acme/support/agent.prompt (structural)
exit=1
$ promptctl diff HEAD --fail-on new
diff: 1 prompt(s) match -fail-on new: acme/support/new.prompt (new)
exit=1
$ promptctl diff -fail-on bogus
-fail-on: unknown verdict "bogus" (want new, structural, tweak, minor)
usage: promptctl diff [-fail-on verdicts] [ref]
exit=2

Fixes #3

🤖 Generated with Claude Code

promptctl diff exited 0 whatever the verdict, so CI had to grep for
"=> structural", and a prompt added since the ref was diffed against an
empty file and reported as "structural".

diff now takes -fail-on, a comma-separated list of verdicts (new,
structural, tweak, minor). It prints the full diff and exits 1 if any
prompt's verdict is in the list. Without the flag the exit code is 0 as
before. A prompt absent from the ref now reads "=> new". Flags may come
before or after the ref.

Fixes #3

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sujal-maheshwari2004
sujal-maheshwari2004 merged commit 6654d01 into main Oct 18, 2026
1 check passed
@sujal-maheshwari2004
sujal-maheshwari2004 deleted the fix/3-diff-exit-code branch October 18, 2026 17:49
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.

promptctl diff always exits 0, even on a structural verdict

1 participant