Skip to content

fix: support GitLab work-item note verification - #7

Merged
eyevanovich merged 1 commit into
mainfrom
fm/firstmate-gitlab-note-verification
Jul 23, 2026
Merged

eyevanovich merged 1 commit into
mainfrom
fm/firstmate-gitlab-note-verification

Conversation

@eyevanovich

Copy link
Copy Markdown
Owner

Intent

Fix the live GitLab note-verification regression blocking completion of KissCut issue 146 after the guarded GitLab workflow changes. Preserve idempotence so an existing note is reused without duplicates, and retain trusted-project, positive-resource-ID, authenticated-author, exact-body, non-system-note, regular-file, and noteable-resource guards. Use the current GitLab work-item-backed issue note response shape, audit the shared issue and merge-request note creation/list/read-back/pagination/body-encoding identity path together, and batch only directly implied note defects rather than broadening scope. Add deterministic live-shape fixture coverage and validate focused forge behavior, lint, and the portable suite. Do not mutate KissCut issue 146 from this fix task.

What Changed

  • Accept GitLab work-item-backed issue notes while verifying the trusted project, noteable resource ID and type, author, exact body, and non-system status.
  • Preserve idempotent issue and merge-request note creation by matching existing notes against their underlying resource identity before posting.
  • Add a deterministic live-shape fixture and focused coverage for work-item responses, body encoding, pagination, and duplicate suppression.

Risk Assessment

✅ Low: Captain, the change is well-bounded and satisfies the authoritative note-verification intent; the only finding is a non-functional simplification opportunity.

Testing

The already-passing portable baseline was supplemented with focused GitLab forge mutation testing and an end-to-end CLI trace; work-item-shaped issue notes verify successfully, preserve exact encoded content, reuse the existing note without duplicates, and retain the shared issue/MR safety guards, with no live mutation of KissCut issue 146.

Evidence: Focused forge mutation test transcript
ok - issue claim sends explicit JSON media type and preserves array encoding
ok - live work-item note shape verifies exact resource and suppresses duplicates
ok - issue creation validates labels, optional claim, identity, and canonical read-back
ok - issue claim, status, note, close, reopen, and release converge safely
ok - already-correct issue claims, statuses, and label deltas are no-ops
ok - issue release can return self-owned work to the ready queue without clobbering labels
ok - issue mutations cannot steal or bypass exact ownership
ok - missing, archived, and malformed label metadata blocks mutations
ok - malformed targets, labels, usernames, and non-regular note files are rejected
ok - issue API identity rejects foreign, mismatched, and malformed work-item URLs
ok - untrusted projects and API failures never report a successful mutation
ok - issue and note mutations require deterministic matching read-back
ok - merge-request claim, status, labels, notes, lifecycle, and release converge safely
ok - merge-request workflow labels require status and release commands
ok - merge-request mutations preserve project, author, branch, head, and API guards
ok - issue creation and comments surface API and verification failures
Evidence: End-to-end GitLab note CLI trace showing first creation, exact body preservation, reuse on retry, pagination, and a single POST
+ 6: set -u
++ 9: dirname tests/fm-forge-mutations.test.sh
+ 9: . tests/lib.sh
++ 23: '[' -n '' ']'
++ 26: FM_TEST_LIB_SOURCED=1
++ 35: export FM_GATE_REFUSE_BYPASS=1
++ 35: FM_GATE_REFUSE_BYPASS=1
++++ 40: dirname tests/lib.sh
+++ 40: cd tests/..
+++ 40: pwd
++ 40: ROOT=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4
++ 45: unset GIT_CONFIG_COUNT GIT_CONFIG_PARAMETERS
++ 46: IFS=
++ 46: read -r variable
+++ 48: compgen -A variable GIT_CONFIG_KEY_
+++ 48: compgen -A variable GIT_CONFIG_VALUE_
++ 49: export GIT_CONFIG_GLOBAL=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixture.gitconfig
++ 49: GIT_CONFIG_GLOBAL=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixture.gitconfig
++ 69: FM_TEST_CLEANUP_DIRS=()
++ 11: fm_test_tmproot fm-forge-mutations-tests
++ 79: local prefix=fm-forge-mutations-tests root
+++ 80: mktemp -d /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.XXXXXX
++ 80: root=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB
++ 81: '[' 0 -eq 0 ']'
++ 82: trap fm_test_cleanup EXIT
++ 84: FM_TEST_CLEANUP_DIRS+=("$root")
++ 85: printf '%s\n' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB
++ 1: fm_test_cleanup
++ 72: local d
++ 73: for d in "${FM_TEST_CLEANUP_DIRS[@]:-}"
++ 74: '[' -n /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB ']'
++ 74: rm -rf /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB
+ 11: TMP=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB
+ 12: ADAPTER=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/bin/fm-forge.sh
+ 13: REPO=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo
++ 14: fm_fakebin /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB
++ 95: local dir=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB fakebin=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin
++ 96: mkdir -p /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin
++ 97: printf '%s\n' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin
+ 14: FAKEBIN=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin
+ 15: LOG=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log
+ 16: ISSUE_STATE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json
+ 17: MR_STATE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json
+ 18: ISSUE_NOTES=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json
+ 19: MR_NOTES=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json
+ 20: WORK_ITEM_NOTE_FIXTURE=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixtures/gitlab-work-item-note.json
+ 21: MUTATED=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated
+ 23: fm_git_init_commit /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo
+ 125: local dir=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo
+ 126: mkdir -p /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo
+ 127: git -C /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo init -q
++ 128: basename /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo
+ 128: printf '# %s\n' repo
+ 129: git -C /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo add README.md
+ 130: git -C /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo -c 'user.name=Firstmate Tests' -c [email protected] commit -qm initial
+ 24: git -C /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo remote add origin [email protected]:kisscut-museum/kisscut-platform.git
+ 25: git -C /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo checkout -q -b fm/fix
+ 27: cat
+ 347: chmod +x /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin/glab
+ 797: test_live_415_regression_claim_uses_json_media_type
+ 375: local out
+ 376: reset_case
+ 365: :
+ 366: rm -f /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated
++ 377: FM_FAKE_ISSUE_OWNER=none
++ 377: run_adapter issue-claim /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo 7
++ 350: PATH=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin:/Users/ipiesh/.codex/tmp/arg0/codex-arg0wM5SxM:/nix/store/ygxqin6ydzjfawywqpp5pal8wv6sf5bh-python3-3.13.13/bin:/nix/store/yggg7hbh9bi0p4c44npy2mdyjbj5d37h-grc-1.13/bin:/Users/ipiesh/.local/bin:/Users/ipiesh/go/bin:/Users/ipiesh/.cargo/bin:/opt/homebrew/bin:/Users/ipiesh/.nix-profile/bin:/etc/profiles/per-user/ipiesh/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ipiesh/bin:/opt/homebrew/sbin:/usr/local/sbin
++ 350: FM_FAKE_GLAB_LOG=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log
++ 350: FM_FAKE_ISSUE_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json
++ 350: FM_FAKE_MR_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json
++ 350: FM_FAKE_ISSUE_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json
++ 350: FM_FAKE_MR_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json
++ 350: FM_FAKE_WORK_ITEM_NOTE_FIXTURE=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixtures/gitlab-work-item-note.json
++ 350: FM_FAKE_MUTATED_MARKER=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated
++ 350: FM_FORGE_HOSTS_FILE=
++ 350: GITLAB_TOKEN=AMBIENT
++ 350: GITLAB_ACCESS_TOKEN=AMBIENT
++ 350: OAUTH_TOKEN=AMBIENT
++ 350: GLAB_ENABLE_CI_AUTOLOGIN=true
++ 350: CI_JOB_TOKEN=AMBIENT
++ 350: /Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/bin/fm-forge.sh issue-claim /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo 7
+ 377: out='{"forge":"gitlab","host":"gitlab.com","project":"kisscut-museum/kisscut-platform","issue":{"iid":7,"title":"Fix cutter","state":"opened","url":"https://gitlab.com/kisscut-museum/kisscut-platform/-/work_items/7","description":"Issue body","labels":["bug","status::in-progress"],"author":"ivan","assignees":["mate"],"updated_at":"2026-07-18T00:00:00Z"}}'
+ 379: jq -e '.issue.assignees == ["mate"]'
+ 381: assert_grep 'issues/7 --hostname gitlab.com --method PUT --input - --header Content-Type: application/json' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log 'issue claim JSON media type'
+ 208: grep -F -- 'issues/7 --hostname gitlab.com --method PUT --input - --header Content-Type: application/json' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log
+ 384: assert_grep 'input={"assignee_ids":[42]' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log 'issue claim array

... [243589 bytes truncated] ...

S_FILE=\n++ 350: GITLAB_TOKEN=AMBIENT\n++ 350: GITLAB_ACCESS_TOKEN=AMBIENT\n++ 350: OAUTH_TOKEN=AMBIENT\n++ 350: GLAB_ENABLE_CI_AUTOLOGIN=true\n++ 350: CI_JOB_TOKEN=AMBIENT\n++ 350: /Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/bin/fm-forge.sh issue-create /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo --title \'Create mismatch\' --body-file /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo/create-body.md --label bug\nerror: issue identity does not match trusted repository\nerror: created issue identity could not be verified'
+ 784: rc=1
+ 785: expect_code 1 1 'created issue identity mismatch'
+ 201: local expected=1 actual=1 'label=created issue identity mismatch'
+ 202: '[' 1 = 1 ']'
+ 786: assert_contains $'++ 350: PATH=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin:/Users/ipiesh/.codex/tmp/arg0/codex-arg0wM5SxM:/nix/store/ygxqin6ydzjfawywqpp5pal8wv6sf5bh-python3-3.13.13/bin:/nix/store/yggg7hbh9bi0p4c44npy2mdyjbj5d37h-grc-1.13/bin:/Users/ipiesh/.local/bin:/Users/ipiesh/go/bin:/Users/ipiesh/.cargo/bin:/opt/homebrew/bin:/Users/ipiesh/.nix-profile/bin:/etc/profiles/per-user/ipiesh/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ipiesh/bin:/opt/homebrew/sbin:/usr/local/sbin\n++ 350: FM_FAKE_GLAB_LOG=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log\n++ 350: FM_FAKE_ISSUE_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json\n++ 350: FM_FAKE_MR_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json\n++ 350: FM_FAKE_ISSUE_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json\n++ 350: FM_FAKE_MR_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json\n++ 350: FM_FAKE_WORK_ITEM_NOTE_FIXTURE=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixtures/gitlab-work-item-note.json\n++ 350: FM_FAKE_MUTATED_MARKER=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated\n++ 350: FM_FORGE_HOSTS_FILE=\n++ 350: GITLAB_TOKEN=AMBIENT\n++ 350: GITLAB_ACCESS_TOKEN=AMBIENT\n++ 350: OAUTH_TOKEN=AMBIENT\n++ 350: GLAB_ENABLE_CI_AUTOLOGIN=true\n++ 350: CI_JOB_TOKEN=AMBIENT\n++ 350: /Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/bin/fm-forge.sh issue-create /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo --title \'Create mismatch\' --body-file /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo/create-body.md --label bug\nerror: issue identity does not match trusted repository\nerror: created issue identity could not be verified' identity 'created issue verification refusal'
+ 185: case "$1" in
+ 186: :
+ 788: reset_case
+ 365: :
+ 366: rm -f /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated
++ 790: FM_FAKE_API_FAIL=issue-create
++ 790: run_adapter issue-create /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo --title 'Create failure' --label bug
+ 790: out=$'++ 350: PATH=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin:/Users/ipiesh/.codex/tmp/arg0/codex-arg0wM5SxM:/nix/store/ygxqin6ydzjfawywqpp5pal8wv6sf5bh-python3-3.13.13/bin:/nix/store/yggg7hbh9bi0p4c44npy2mdyjbj5d37h-grc-1.13/bin:/Users/ipiesh/.local/bin:/Users/ipiesh/go/bin:/Users/ipiesh/.cargo/bin:/opt/homebrew/bin:/Users/ipiesh/.nix-profile/bin:/etc/profiles/per-user/ipiesh/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ipiesh/bin:/opt/homebrew/sbin:/usr/local/sbin\n++ 350: FM_FAKE_GLAB_LOG=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log\n++ 350: FM_FAKE_ISSUE_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json\n++ 350: FM_FAKE_MR_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json\n++ 350: FM_FAKE_ISSUE_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json\n++ 350: FM_FAKE_MR_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json\n++ 350: FM_FAKE_WORK_ITEM_NOTE_FIXTURE=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixtures/gitlab-work-item-note.json\n++ 350: FM_FAKE_MUTATED_MARKER=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated\n++ 350: FM_FORGE_HOSTS_FILE=\n++ 350: GITLAB_TOKEN=AMBIENT\n++ 350: GITLAB_ACCESS_TOKEN=AMBIENT\n++ 350: OAUTH_TOKEN=AMBIENT\n++ 350: GLAB_ENABLE_CI_AUTOLOGIN=true\n++ 350: CI_JOB_TOKEN=AMBIENT\n++ 350: /Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/bin/fm-forge.sh issue-create /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo --title \'Create failure\' --label bug\nerror: issue creation failed'
+ 791: rc=1
+ 792: expect_code 1 1 'issue creation API failure'
+ 201: local expected=1 actual=1 'label=issue creation API failure'
+ 202: '[' 1 = 1 ']'
+ 793: assert_contains $'++ 350: PATH=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/fakebin:/Users/ipiesh/.codex/tmp/arg0/codex-arg0wM5SxM:/nix/store/ygxqin6ydzjfawywqpp5pal8wv6sf5bh-python3-3.13.13/bin:/nix/store/yggg7hbh9bi0p4c44npy2mdyjbj5d37h-grc-1.13/bin:/Users/ipiesh/.local/bin:/Users/ipiesh/go/bin:/Users/ipiesh/.cargo/bin:/opt/homebrew/bin:/Users/ipiesh/.nix-profile/bin:/etc/profiles/per-user/ipiesh/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ipiesh/bin:/opt/homebrew/sbin:/usr/local/sbin\n++ 350: FM_FAKE_GLAB_LOG=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/glab.log\n++ 350: FM_FAKE_ISSUE_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue.json\n++ 350: FM_FAKE_MR_STATE_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr.json\n++ 350: FM_FAKE_ISSUE_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/issue-notes.json\n++ 350: FM_FAKE_MR_NOTES_FILE=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mr-notes.json\n++ 350: FM_FAKE_WORK_ITEM_NOTE_FIXTURE=/Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/tests/fixtures/gitlab-work-item-note.json\n++ 350: FM_FAKE_MUTATED_MARKER=/var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/mutated\n++ 350: FM_FORGE_HOSTS_FILE=\n++ 350: GITLAB_TOKEN=AMBIENT\n++ 350: GITLAB_ACCESS_TOKEN=AMBIENT\n++ 350: OAUTH_TOKEN=AMBIENT\n++ 350: GLAB_ENABLE_CI_AUTOLOGIN=true\n++ 350: CI_JOB_TOKEN=AMBIENT\n++ 350: /Users/ipiesh/.no-mistakes/worktrees/2814d4e34fac/01KY67HH2JGNYDV9VCR0WDWXX4/bin/fm-forge.sh issue-create /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.eHx8KB/repo --title \'Create failure\' --label bug\nerror: issue creation failed' 'issue creation failed' 'issue creation failure report'
+ 185: case "$1" in
+ 186: :
+ 794: pass 'issue creation and comments surface API and verification failures'
+ 59: printf 'ok - %s\n' 'issue creation and comments surface API and verification failures'
ok - issue creation and comments surface API and verification failures

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-forge.sh:586 - The existing-note selector duplicates the full trusted note-identity predicate from note_identity_valid(). Extract a shared jq predicate/filter so list-time idempotence matching and read-back verification cannot drift as guards evolve.
✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • Reviewed git diff --unified=100 f68d7c9c455fdf15f4972efaef9f4dc242f93eec..4bab937f7fc8a820aa88e7af6000052fa5608fbe against the authoritative intent.
  • Accepted the previously successful configured portable baseline: command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc".
  • Ran bash tests/fm-forge-mutations.test.sh against the deterministic local GitLab fixture.
  • Ran PS4='+ ${LINENO}: ' bash -x tests/fm-forge-mutations.test.sh to capture end-user CLI JSON and API-call evidence.
  • Verified git status --short remained empty and no .fm-forge-body.* transient snapshots remained.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@eyevanovich
eyevanovich merged commit ad0edda into main Jul 23, 2026
@eyevanovich
eyevanovich deleted the fm/firstmate-gitlab-note-verification branch July 23, 2026 01:40
eyevanovich added a commit that referenced this pull request Jul 23, 2026
## Intent

Autofix the remaining live GitLab WorkItem completion bug after PR #7.
Issue 146 is a trusted self-owned WorkItem whose exact authenticated
completion note appears three times because WorkItem noteable_id is a
separate opaque positive identity from the legacy Issues API .id.
Through the trusted issue-notes endpoint, reuse any existing exact
authenticated non-system WorkItem note without comparing its opaque
noteable_id to the issue API ID and never POST another duplicate;
preserve strict comparable identity checks for legacy Issue and
MergeRequest notes, exact body and author matching, pagination,
malformed-ID rejection, and field-name-only mismatch diagnostics. Also
make issue-close converge both new and already-closed self-owned issues
to closed with all execution/workflow labels removed while preserving
unrelated labels and ownership, without repeating an already-landed
state transition; enforce the directly equivalent MR close invariant.
Keep all fixes and tests within WorkItem note identity/deduplication and
issue/MR close-state convergence, and do not broaden the public API.

## What Changed

- Reuse exact authenticated non-system GitLab WorkItem notes without
comparing their opaque `noteable_id` to the legacy issue ID, while
preserving strict Issue and MergeRequest identity checks and
malformed-ID rejection.
- Make issue and merge-request close operations remove workflow labels,
preserve unrelated metadata, and converge already-closed resources
without repeating the close transition.
- Expand mutation coverage for note deduplication, endpoint-scoped
identity validation, field-only mismatch diagnostics, malformed note
IDs, and idempotent close cleanup.

## Risk Assessment

✅ Low: Captain, the prior correctness findings are resolved and the only
remaining issue is an unused private helper.

## Testing

The previously completed full baseline passed, the focused GitLab
mutation suite passed twice, and its captured CLI/API trace directly
demonstrates WorkItem note reuse, strict legacy identity handling,
malformed-ID rejection, and idempotent issue/MR close-state convergence;
no UI surface was changed, so visual evidence was not applicable.

<details>
<summary>Evidence: GitLab end-user flow evidence</summary>

```text
137:+ out='{"resource":"issue","note":{"id":501,"body":"Live work-item note.\nSecond line: \"quoted\" & UTF-8 café.\n","author":"mate","already":true}}'
172:+ out='{"resource":"issue","note":{"id":501,"body":"Live work-item note.\nSecond line: \"quoted\" & UTF-8 café.\n","author":"mate","already":true}}'
202:+ out='{"resource":"issue","note":{"id":551,"body":"Legacy issue note.\n","author":"mate","already":true}}'
210:+ jq -cn --argjson exact '{"id":651,"body":"Legacy MR note.\n","author":{"id":42,"username":"mate"},"system":false,"noteable_id":8005,"noteable_type":"MergeRequest","project_id":314,"noteable_iid":5}' $'[\n    ($exact | .id=649 | .noteable_type="WorkItem" | .noteable_iid=null),\n    ($exact | .id=650 | .noteable_iid=6),\n    $exact\n  ]'
227:+ out='{"resource":"mr","note":{"id":651,"body":"Legacy MR note.\n","author":"mate","already":true}}'
257:+ jq -cn --rawfile body /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/repo/malformed-existing-note.md $'\n    [{id:0,body:$body,author:{id:42,username:"mate"},system:false,\n      noteable_id:77146,noteable_type:"WorkItem",project_id:314,noteable_iid:null}]'
459:+ out='{"resource":"issue","note":{"id":501,"body":"Worker update.\n","author":"mate","already":true}}'
483:+ jq -e $'.issue.state == "closed" and .issue.labels == ["bug"]\n    and .issue.assignees == ["mate"]'
484:++ count_log '"state_event":"close"'
485:++ local 'pattern="state_event":"close"'
486:++ grep -c -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
504:++ count_log '"state_event":"close"'
505:++ local 'pattern="state_event":"close"'
506:++ grep -c -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
525:++ jq -r .issue.state
595:+ jq -e $'.issue.state == "closed" and .issue.labels == ["bug"]\n    and .issue.assignees == ["mate"]'
596:+ assert_no_grep '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log 'issue close retry repeated an already-landed state transition'
597:+ grep -F -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
644:+ jq -e $'.mr.state == "closed" and .mr.labels == ["backend"]\n    and .mr.assignees == []'
645:+ assert_no_grep '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log 'merge-request close retry repeated an already-landed state transition'
646:+ grep -F -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
757:++ count_log 'input={"add_labels":"docs","remove_labels":"bug"}'
758:++ local 'pattern=input={"add_labels":"docs","remove_labels":"bug"}'
759:++ grep -c -- 'input={"add_labels":"docs","remove_labels":"bug"}' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
1297:+ out='{"resource":"mr","note":{"id":601,"body":"MR update.\n","author":"mate","already":true}}'
1323:+ jq -e '.mr.state == "closed" and .mr.labels == ["docs"]'
1341:++ jq -r .mr.state
```
</details>
<details>
<summary>Evidence: Targeted mutation-suite transcript</summary>

```text
ok - issue claim sends explicit JSON media type and preserves array encoding
ok - live work-item note shape verifies exact resource and suppresses duplicates
ok - note list matching and read-back share strict endpoint-scoped identity
ok - malformed created note IDs cannot pass read-back verification
ok - malformed matching note IDs fail closed without duplicate posts
ok - issue creation validates labels, optional claim, identity, and canonical read-back
ok - issue claim, status, note, close, reopen, and release converge safely
ok - close retries remove workflow labels without repeating landed transitions
ok - already-correct issue claims, statuses, and label deltas are no-ops
ok - issue release can return self-owned work to the ready queue without clobbering labels
ok - issue mutations cannot steal or bypass exact ownership
ok - missing, archived, and malformed label metadata blocks mutations
ok - malformed targets, labels, usernames, and non-regular note files are rejected
ok - issue API identity rejects foreign, mismatched, and malformed work-item URLs
ok - untrusted projects and API failures never report a successful mutation
ok - issue and note mutations require deterministic matching read-back
ok - merge-request claim, status, labels, notes, lifecycle, and release converge safely
ok - merge-request workflow labels require status and release commands
ok - merge-request mutations preserve project, author, branch, head, and API guards
ok - issue creation and comments surface API and verification failures
```
</details>

## Pipeline

Updates from [git push
no-mistakes](https://github.com/kunchenguid/no-mistakes)

<details>
<summary>✅ **intent** - passed</summary>

✅ No issues found.

</details>

<details>
<summary>✅ **Rebase** - passed</summary>

✅ No issues found.

</details>

<details>
<summary>⚠️ **Review** - 1 info</summary>

- 🚨 `bin/fm-forge.sh:591` - The intent requires “never POST another
duplicate” and preserving “malformed-ID rejection.” `find_matching_note`
silently skips an otherwise exact authenticated non-system note whose
`.id` is malformed; if no valid duplicate follows, `post_note` falls
through to POST. Reject this case with an `id`-only diagnostic instead
of posting.
- ⚠️ `bin/fm-forge.sh:1117` - The close path now changes workflow
labels, but the script header still states that workflow labels are
changed only by claim, status, and release commands. Update that safety
contract to include close cleanup.
- ℹ️ `bin/fm-forge.sh:1117` - Issue and MR close duplicate
workflow-label removal, expected-label calculation, idempotence, and
payload construction. Extract the shared close-state calculation so
these directly equivalent invariants cannot drift.

🔧 Fix: Fix note deduplication and close-state convergence
1 info still open:
- ℹ️ `bin/fm-forge.sh:575` - `note_identity_valid()` is now unused;
matching and required verification both call
`note_identity_mismatches()` directly. Remove this dead wrapper to
simplify the identity helper surface.

</details>

<details>
<summary>✅ **Test** - passed</summary>

✅ No issues found.
- `command -v tmux >/dev/null || { echo "tmux is required for e2e tests"
>&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t
=="; bash "$t" || rc=1; done; exit "$rc"`
- <code>Pre-run baseline: `command -v tmux &gt;/dev/null || { echo
&kunchenguid#34;tmux is required for e2e tests&kunchenguid#34; &gt;&amp;2; exit 1; }; tmux -V;
rc=0; for t in tests/*.test.sh; do echo &kunchenguid#34;== $t ==&kunchenguid#34;; bash
&kunchenguid#34;$t&kunchenguid#34; || rc=1; done; exit &kunchenguid#34;$rc&kunchenguid#34;`</code>
- `bash tests/fm-forge-mutations.test.sh`
- <code>`bash -x tests/fm-forge-mutations.test.sh` with filtered
CLI-response and mutation evidence captured to
`gitlab-user-flow-evidence.txt`</code>
- <code>Verified the testing run left the git worktree clean with `git
status --short`</code>

</details>

<details>
<summary>✅ **Document** - passed</summary>

✅ No issues found.

</details>

<details>
<summary>✅ **Lint** - passed</summary>

✅ No issues found.

</details>

<details>
<summary>✅ **Push** - passed</summary>

✅ No issues found.

</details>

---------

Co-authored-by: Ivan Miles Piesh <[email protected]>
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