-
Notifications
You must be signed in to change notification settings - Fork 0
fix(cli): tree-canonical range hash for CI verify #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
chtnnh
wants to merge
1
commit into
main
Choose a base branch
from
fix/ci-verify-tree-canonical-hash
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| #!/usr/bin/env bash | ||
| # CI-shaped verify smoke: after a real commit trailer, strip local seal/gate | ||
| # artifacts and assert know-code verify still passes (what Actions sees). | ||
| set -euo pipefail | ||
|
|
||
| ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| SMOKE="$(mktemp -d)" | ||
| export KNOW_CODE_ATTEST_PASSPHRASE="ci-smoke-verify-passphrase" | ||
| export KNOW_CODE_ATTEST_HOME="$(mktemp -d)" | ||
| KC="$ROOT/packages/cli/dist/index.js" | ||
| cleanup() { rm -rf "$SMOKE" "$KNOW_CODE_ATTEST_HOME"; } | ||
| trap cleanup EXIT | ||
|
|
||
| if [[ ! -f "$KC" ]]; then | ||
| echo "smoke-verify-ci: missing $KC — run npm run build first" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| cd "$SMOKE" | ||
| git init -b main --template= >/dev/null | ||
| git config user.email "smoke-verify@test" | ||
| git config user.name "smoke-verify" | ||
| # Bare origin so merge-base resolution matches CI (origin/main present). | ||
| git init --bare "$SMOKE/remote.git" --template= >/dev/null | ||
| git remote add origin "$SMOKE/remote.git" | ||
|
|
||
| echo "base" > README.md | ||
| git add README.md | ||
| git -c commit.gpgsign=false commit -m "init" >/dev/null | ||
| git push -u origin main >/dev/null | ||
|
|
||
| node "$KC" init --level lite --require-trailer | ||
| node "$KC" attest-init | ||
| node "$KC" range begin | ||
|
|
||
| echo "feature" >> README.md | ||
| git add README.md | ||
|
|
||
| HASH="$(node "$KC" hash)" | ||
| node "$KC" taught --hash "$HASH" | ||
|
|
||
| ATTEST_JS="$ROOT/packages/cli/dist/attest.js" | ||
| node --input-type=module -e " | ||
| const { writeAnswers } = await import(process.argv[1]); | ||
| writeAnswers(process.cwd(), { | ||
| diffHash: process.argv[2], | ||
| level: 'lite', | ||
| answers: [{ id: 'q1', answer: 'smoke verify' }], | ||
| submittedAt: new Date().toISOString() | ||
| }); | ||
| " "file://${ATTEST_JS}" "$HASH" | ||
|
|
||
| DIGEST="$(node -e "const f=require('fs');const a=JSON.parse(f.readFileSync('.know-code/answers.json','utf8'));console.log(a.answersDigest)")" | ||
|
|
||
| node --input-type=module -e " | ||
| import { writeFileSync } from 'node:fs'; | ||
| writeFileSync('.know-code/grade-proposal.json', JSON.stringify({ | ||
| version: 1, | ||
| diffHash: process.argv[1], | ||
| answersDigest: process.argv[2], | ||
| proposedScore: 1, | ||
| passed: true, | ||
| perQuestion: [{ id: 'q1', score: 1, feedback: 'ok' }], | ||
| rubricVersion: '1', | ||
| gradedBy: 'smoke', | ||
| gradedAt: new Date().toISOString(), | ||
| level: 'lite', | ||
| }, null, 2) + '\n'); | ||
| " "$HASH" "$DIGEST" | ||
|
|
||
| node "$KC" grade --accept --hash "$HASH" --level lite --passphrase "$KNOW_CODE_ATTEST_PASSPHRASE" | ||
| node "$KC" pass --level lite --hash "$HASH" --passphrase "$KNOW_CODE_ATTEST_PASSPHRASE" | ||
|
|
||
| node "$KC" commit -m "feat: smoke verify feature" | ||
|
|
||
| # Mimic Actions: no local trust anchors — only public git history. | ||
| rm -f \ | ||
| .know-code/gate.json \ | ||
| .know-code/range-seal.json \ | ||
| .know-code/sealed-head-binding.json \ | ||
| .know-code/taught.json \ | ||
| .know-code/grade.json \ | ||
| .know-code/grade-proposal.json \ | ||
| .know-code/answers.json \ | ||
| .know-code/quiz.json | ||
| printf '%s\n' '{' \ | ||
| ' "level": "lite",' \ | ||
| ' "baseBranch": "main",' \ | ||
| ' "requireTrailer": true,' \ | ||
| ' "rangeMode": "auto"' \ | ||
| '}' > .know-code/config.json | ||
|
|
||
| set +e | ||
| OUT="$(node "$KC" verify 2>&1)" | ||
| code=$? | ||
| set -e | ||
| echo "$OUT" | ||
| test "$code" -eq 0 | ||
| echo "$OUT" | grep -q "HEAD trailer verified" | ||
|
|
||
| # Negative: fake trailer must fail. | ||
| git -c commit.gpgsign=false commit --amend --no-verify -m "$(cat <<EOF | ||
| feat: smoke verify feature | ||
|
|
||
| Know-Code-Verified: $(printf 'a%.0s' {1..64}) | ||
| EOF | ||
| )" >/dev/null | ||
|
|
||
| set +e | ||
| node "$KC" verify >/dev/null 2>&1 | ||
| bad=$? | ||
| set -e | ||
| test "$bad" -ne 0 | ||
|
|
||
| echo "SMOKE VERIFY CI OK" |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Range hash skips lock-safe write-tree
Medium Severity
computeRangeDiffContextnow depends onwrite-treefor the tree-canonical tip, but calls rawgit write-treewith anEMPTY_TREEfallback instead ofindexTreeOid. Under pre-commitindex.lock, that failure yields a wrong range hash (empty-tree material) rather than the real index tree the rest of the gate path already resolves lock-safely.Reviewed by Cursor Bugbot for commit 9e1f785. Configure here.