Skip to content

refactor(coordinator): migrate governance library diff workflow - #486

Merged
monkey1sai merged 1 commit into
mainfrom
fix/issue-397-governance-library-diff-workflow
Aug 10, 2026
Merged

monkey1sai merged 1 commit into
mainfrom
fix/issue-397-governance-library-diff-workflow

Conversation

@monkey1sai

@monkey1sai monkey1sai commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Complete the Governance Library Workflow cutover for POST /api/governance-library/diffs.
  • Resolve base and target references from one tree snapshot, preserve trusted optional-field shaping and opaque upstream forwarding, and remove only the superseded inline helpers.
  • Keep the public route/schema, generic governance proxy, viewer, deploy, security, and Kit surfaces unchanged.

Closes #397

AI Coding Governance

Item Result
Change lane G
Behavior contract changed no
Linked issue Closes #397; prerequisite #396 closed by merged PR #401
Requirement source issue
CODEOWNERS / owner review requested from @monkey1sai-blip after required CI is green
GitNexus evidence Pre-edit impact reported risk_level=CRITICAL for createCoordinatorApp / GovernanceLibraryWorkflow, but the index was stale and collision-prone. Linked-worktree health reports current_checkout_trust=unknown; compare detect-changes is unavailable and is not claimed as passed. Sol/Terra/Luna sign-off plus raw source, exact diff, and executable tests are the explicit fallback evidence.
Browser E2E evidence not user-facing; viewer governance-client wire test 12/12 passed
Agent workflow changed? no
Required checks expected CI / Agent Governance / PR Metadata Contract / Governance Base Audit / CodeQL

Frontend Verification

Not applicable: this is a coordinator-internal, behavior-preserving architecture cutover and changes no frontend path.

Deploy Path Verification

Not applicable: no runtime packaging, Docker, Kit, viewer, port, environment, or deploy path changed.

Windows On-Demand Verification

Not applicable: machine-derived changed paths do not match a Windows verification tier.

Self-Referential Bootstrap

Item Result
Self-referential bootstrap no
Bootstrap ledger entry not applicable
Bootstrap reason not applicable

Validation

  • TDD RED: targeted suite failed in 8 expected cases because runLibraryDiff / postDiff did not yet exist; existing route parity tests stayed green.
  • npm run build in bim-review-coordinator: passed.
  • npx vitest run tests/governance-library-workflow.test.ts tests/governance-library-http-adapter.test.ts tests/governance-library-routes.test.ts: 3 files, 46 tests passed.
  • npm run verify in bim-review-coordinator: build passed; 69 files, 856 tests passed.
  • npx vitest run src/console/governanceClient.test.ts in web-viewer-sample: 1 file, 12 tests passed.
  • Raw ownership gate: exactly one POST /api/governance-library/diffs Express owner; zero runtime references to removed inline helpers.
  • git diff --check: passed.
  • L1 Luna Standards review: accepted after the ADR return-type mismatch was fixed and rechecked.
  • L2 Terra Spec/adversarial review: accepted with no merge blocker.
  • L3 Sol/max apex review: accepted for commit/push/open PR; no blocker or scope drift, with GitNexus uncertainty retained as an explicit warning.

Known Risks

  • GitNexus current-worktree detect-changes remains unavailable because the linked-worktree index trust is unknown; no GitNexus pass is claimed.
  • The ADR deliberately retains path-masking duplication in the frozen generic governance proxy.
  • The internal throwing-getter lookup case is normalized to 502 per the accepted ADR; behavior-preserving parity refers to the real HTTP JSON tree path.

Summary by CodeRabbit

  • New Features

    • Added governance-library model comparison support.
    • Comparisons can optionally include geometry and model-version identifiers.
    • Responses preserve upstream status and content while masking server file paths.
    • Missing or unavailable model versions now return clear error outcomes.
  • Bug Fixes

    • Standardized handling of validation, missing-version, service-unavailable, and upstream comparison errors.
  • Tests

    • Added coverage for successful comparisons, optional fields, error handling, response forwarding, and path redaction.

Copilot AI balanced review requested due to automatic review settings August 10, 2026 20:54
@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a72cfbf-82ec-4dfe-864d-00d695758afa

📥 Commits

Reviewing files that changed from the base of the PR and between 4ee3f0c and 63c293e.

📒 Files selected for processing (6)
  • bim-review-coordinator/src/app.ts
  • bim-review-coordinator/src/services/governanceLibraryHttpAdapter.ts
  • bim-review-coordinator/src/services/governanceLibraryWorkflow.ts
  • bim-review-coordinator/tests/governance-library-http-adapter.test.ts
  • bim-review-coordinator/tests/governance-library-routes.test.ts
  • bim-review-coordinator/tests/governance-library-workflow.test.ts

📝 Walkthrough

Walkthrough

The governance library diff route now delegates tree resolution, diff request construction, upstream forwarding, error classification, and path redaction to GovernanceLibraryWorkflow. The HTTP adapter posts diff requests and returns opaque upstream responses. Tests cover success and failure mappings.

Changes

Governance Library Diff

Layer / File(s) Summary
Diff workflow contracts and resolution
bim-review-coordinator/src/services/governanceLibraryWorkflow.ts, bim-review-coordinator/tests/governance-library-workflow.test.ts
Adds diff command and payload contracts. Resolves base and target versions from one tree snapshot. Maps missing versions and transport failures. Preserves optional fields and redacts supported server paths.
Diff HTTP adapter
bim-review-coordinator/src/services/governanceLibraryHttpAdapter.ts, bim-review-coordinator/tests/governance-library-http-adapter.test.ts
Adds postDiff for JSON requests to /api/diffs. Returns upstream status, content type, and text body.
Route delegation and HTTP behavior
bim-review-coordinator/src/app.ts, bim-review-coordinator/tests/governance-library-routes.test.ts
Removes local governance diff helpers. Delegates to runLibraryDiff and preserves status mappings, optional-field behavior, upstream metadata, and path masking.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant GovernanceLibraryRoute
  participant GovernanceLibraryWorkflow
  participant GovernanceLibraryHttpAdapter
  Client->>GovernanceLibraryRoute: POST /api/governance-library/diffs
  GovernanceLibraryRoute->>GovernanceLibraryWorkflow: runLibraryDiff(command)
  GovernanceLibraryWorkflow->>GovernanceLibraryHttpAdapter: load tree and POST /api/diffs
  GovernanceLibraryHttpAdapter-->>GovernanceLibraryWorkflow: upstream response
  GovernanceLibraryWorkflow-->>GovernanceLibraryRoute: mapped outcome with redacted body
  GovernanceLibraryRoute-->>Client: HTTP response
Loading

Possibly related issues

  • monkey1sai/AI-BIM-governance#395 — Defines the broader governance library workflow cutover implemented by this change.

Possibly related PRs

Suggested reviewers: monkey1sai-blip

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the coordinator migration of the governance library diff workflow.
Linked Issues check ✅ Passed The changes implement issue #397 by moving diff handling to the workflow and port while preserving resolution, forwarding, errors, masking, and tests.
Out of Scope Changes check ✅ Passed The changes are limited to the governance diff workflow, adapter, route integration, and related tests described in issue #397.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-397-governance-library-diff-workflow

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

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR completes the Governance Library Workflow cutover for POST /api/governance-library/diffs in the coordinator, following the already-merged rule-run migration (#401, closing #396). The inline diff logic in the composition root (createCoordinatorApp) is replaced by a delegation to the operation-specific GovernanceLibraryWorkflow.runLibraryDiff, backed by a narrow port method on the production HTTP adapter. The public route/schema, generic governance proxy, and all viewer/deploy/security surfaces are unchanged, and only the now-unreferenced inline helpers are removed.

Changes:

  • Add runLibraryDiff to GovernanceLibraryWorkflow (with GovernanceLibraryDiffBody/GovernanceLibraryDiffCommand types and a postDiff port method) that resolves base and target from one tree snapshot, shapes optional fields, forwards opaquely, and redacts server paths.
  • Add postDiff to GovernanceLibraryHttpAdapter (POST /api/diffs, no timeout/retry, per-call base resolution).
  • Rewrite the diff Express route to delegate to the workflow and map closed outcomes to the existing 404/502/forward semantics, and remove the superseded inline helpers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
bim-review-coordinator/src/services/governanceLibraryWorkflow.ts Adds diff body/command types, the postDiff port method, and runLibraryDiff with one-tree resolution, optional-field shaping, and path redaction.
bim-review-coordinator/src/services/governanceLibraryHttpAdapter.ts Adds the postDiff HTTP adapter method targeting /api/diffs.
bim-review-coordinator/src/app.ts Delegates the diff route to the workflow and removes the now-unreferenced inline helpers (findLibraryVersionPath, redactServerPathsForBrowser, fetchGovernanceLibraryTree, forwardLibraryPostToGovernance).
bim-review-coordinator/tests/governance-library-workflow.test.ts Adds runLibraryDiff seam tests (one-tree resolution, omission, per-side version-not-found, throwing getter, transport/POST failures).
bim-review-coordinator/tests/governance-library-routes.test.ts Adds diff route integration coverage for upstream status/content-type/opaque-body/path-masking parity, optional-field semantics, and per-side missing versions.
bim-review-coordinator/tests/governance-library-http-adapter.test.ts Extends adapter tests to assert postDiff URL, headers, body, no signal, and per-call base resolution.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@codex-tri-adversarial-bot codex-tri-adversarial-bot 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.

Codex Tri-Adversarial Bot

Automated tri-adversarial ship-gate (L0 terra triage / L1 tier-routed lens fanout / L2 refute-by-default / L3 sol apex — Codex models).
Mapped event: COMMENT


Codex Tri-Adversarial ship-gate — PR #486

  • Repo head: fix/issue-397-governance-library-diff-workflow @ 63c293e
  • Base: main @ 4ee3f0c
  • Files changed: 6
  • Engine: four-model tri-adversarial gate on Codex — L0 triage gpt-5.6-terra/low; L1 lens finders routed gpt-5.6-terra/low → gpt-5.6-luna/medium → gpt-5.5/xhigh (security floor gpt-5.5); L2 refute-by-default gpt-5.5/xhigh, top-tier findings refuted by gpt-5.6-sol/xhigh (every refutation cross-model); L3 apex gpt-5.6-sol/max. 誠實聲明:層級與 Claude 三層 gate 同構(terra≈haiku、luna≈sonnet、gpt-5.5≈opus、sol≈fable),但模型池是 Codex 的,非 Anthropic 的。

Verdict

SHIP

  • 阻擋門檻 severity: critical, high
  • mapped GitHub event: COMMENT
  • ℹ️ 判定為 SHIP,但刻意不送 APPROVE:GitHub App 的 approving review 不計入 required_approving_review_count(2026-07-31 實測)。本報告是證據,approving 那一票請由真人帳號投。

Difficulty & routing

  • overall: high (source: terra-triage)
  • lens tiers: correctness→gpt-5.5, security→gpt-5.5, simplification→gpt-5.6-luna, test-gap→gpt-5.5

Layer stats

  • L1: raw=4 deduped=4 finder_failures=0
  • L2: confirmed=1 refuted=3 unverified=0
  • L3 final: 1

Findings (final, after apex)

[low] HTTP adapter duplicates identical POST/reply plumbing

  • id: S1 lens: simplification file: bim-review-coordinator/src/services/governanceLibraryHttpAdapter.ts line: 39
  • provenance: finder=gpt-5.6-luna refuter=gpt-5.5 (cross-model) L2=confirmed
  • evidence: The new postDiff repeats the adjacent postRuleRun implementation: POST with JSON headers/body, then map status, content-type fallback, and response.text(). Only the endpoint and payload type differ.
  • why: KEEP at low severity. This is genuine duplicated plumbing with two future change sites, but it is not a behavioral defect or merge blocker.
  • proposed fix: Extract a private postJson(path, body) helper and delegate both postRuleRun and postDiff to it.

Killed (did not survive L2/L3)

  • SEC-1 [medium] Client-supplied model version IDs are forwarded without validation or binding to resolved library versions — The diff does not introduce this behavior: the removed app.ts implementation already forwarded both optional client-supplied IDs unchanged after resolving the IFC paths. The refactor preserves that outbound body exactly. Moreover, the IDs are not used here for path resolution or authorization, and t
  • TG-001 [medium] invalid_ids branch for diff route has no adversarial coverage and appears unreachable from new workflow tests — The diff does not establish an invalid_ids contract for runLibraryDiff. Static control flow shows that method can return only unavailable, version_not_found, or forwarded; therefore the route’s invalid_ids case is unreachable, likely because it switches over a shared, overly broad outcom
  • S2 [low] Port expansion forces unrelated fakes to add dead implementations — The finding is overstated. The diff shows postDiff added to one shared governance-library workflow port, and the extra postDiff() { throw ... } implementations are localized test doubles in the same workflow test file. Production has a single cohesive HTTP adapter for the same upstream governanc

Summary

KEEP S1 at low severity: postDiff duplicates postRuleRun request and reply handling. This is a non-blocking cleanup; extracting a small shared helper would prevent the two paths from drifting.

Agent calls

  • 10/10 ok, engine wall-clock 281.6s

VERDICT

SHIP

VERDICT: SHIP

@monkey1sai-blip monkey1sai-blip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved by monkey1sai-blip (the reviewer account pinned by the repo's merge governance).

Submitted through scripts/blip_review.py — a scripted approval carrying the operator's authority, pinned to head 63c293ed1064125ca252cd224c90c252226bb8bc. This is the mechanism the GitHub App cannot satisfy: an App's approving review does not count toward required_approving_review_count.

@monkey1sai
monkey1sai merged commit a93c5a3 into main Aug 10, 2026
40 checks passed
@monkey1sai
monkey1sai deleted the fix/issue-397-governance-library-diff-workflow branch August 10, 2026 21:11
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.

Migrate governance library diff and contract inline helpers

3 participants