Compare commits

..

22 Commits

Author SHA1 Message Date
616a94fdc3 ci: retrigger gate-check-v3 for core-devops approval
Some checks failed
E2E API Smoke Test / detect-changes (pull_request) Successful in 30s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 31s
Harness Replays / detect-changes (pull_request) Successful in 18s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 26s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 11s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 19s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 39s
qa-review / approved (pull_request) Failing after 22s
security-review / approved (pull_request) Failing after 19s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Successful in 48s
gate-check-v3 / gate-check (pull_request) Failing after 33s
sop-checklist / all-items-acked (pull_request) [info tier:low] acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: comprehensive-testing, l
sop-checklist-gate / gate (pull_request) Successful in 15s
sop-tier-check / tier-check (pull_request) Successful in 15s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m20s
CI / Canvas (Next.js) (pull_request) Successful in 6s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 5s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (pull_request) Successful in 1m32s
CI / Python Lint & Test (pull_request) Successful in 7s
lint-continue-on-error-tracking / lint-continue-on-error-tracking (pull_request) Successful in 1m58s
Lint pre-flip continue-on-error / Verify continue-on-error flips have run-log proof (pull_request) Successful in 1m49s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 14s
lint-required-context-exists-in-bp / lint-required-context-exists-in-bp (pull_request) Successful in 2m2s
Harness Replays / Harness Replays (pull_request) Successful in 9s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 11s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 1m49s
CI / Platform (Go) (pull_request) Failing after 3m38s
CI / all-required (pull_request) Successful in 3s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Failing after 3m16s
2026-05-13 09:06:08 +00:00
a132861920 ci: retrigger gate-check-v3 for core-devops approval 2026-05-13 09:06:08 +00:00
86b2935755 [core-be-agent] fix hub_test.go: unbuffered channel hang + pointer identity
Root cause of CI hang (CI / Platform (Go) failing after 2m11s):

1. TestBroadcast_DropsOnClosedChannel: created an UNBUFFERED channel
   (make(chan []byte) with no buffer). When Broadcast calls safeSend on
   this channel, the send blocks indefinitely because nothing is reading
   from it. go test hangs forever waiting for the test to complete.
   Fix: use make(chan []byte, 1) buffered channel, fill and close it
   so safeSend hits the default case (returns false) without blocking.

2. Pointer identity: Broadcast tests used anonymous struct literals in
   h.clients map assignments, but Go map keys store copies of structs.
   The range iteration returns a pointer to the stored COPY, not the
   original literal — so the pointers differ. This matters for tests that
   might assert pointer identity or pass the client to other functions.
   Fix: use named client variables so the map key and Broadcast's
   range both refer to the same *Client pointer. Applied to all
   Broadcast tests defensively.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
7ebdbe102c [core-be-agent] fix type mismatch: return sqlmock.Sqlmock (interface), not *sqlmock.Sqlmock
sqlmock.New() returns (Sqlmock, error) where Sqlmock is the interface
type, not a pointer. setupTestDB correctly returns sqlmock.Sqlmock (interface),
but setupWorkspaceCrudTest and setupInstructionsTestDB incorrectly declared
*sqlmock.Sqlmock (pointer to interface). In Go, *Interface is a distinct
type from Interface — this would be a compile error.

Root cause: copy-paste from setupWorkspaceCrudTest where the original author
assumed *sqlmock.Sqlmock was the correct type.

Fix: change both setup functions to return sqlmock.Sqlmock (interface) to
match what sqlmock.New() actually returns.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
446ef9c467 [core-be-agent] fix vet warnings: unused variables in hub_test and bundle_helpers_test
Per QA review of PR #794:

1. hub_test.go TestNewHub_WithAccessChecker: `called` was set but never
   read (unused variable → go vet failure). Added assertion that checks
   `called` is true after verifying the access checker was invoked.

2. bundle_helpers_test.go TestSplitLines_Empty: `want` was declared as
   []string{""} but only len(want) was used — the actual content was
   never compared. Fixed to assert len(got)==1 && got[0]=="", which
   validates the correct split behavior for an empty string.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
2e261e1b91 [core-be-agent] fix tests: routing engine + setupInstructionsTest
Two compounding test bugs were causing CI failures in the Platform (Go) job:

1. workspace_crud_test.go: 9 Update tests still registered routes on a
   separate r2 := gin.New() but called r.ServeHTTP() on the original
   engine from setupWorkspaceCrudTest. This sent requests to r (which
   had no PATCH route) → 404 instead of the expected validation error.
   Fixed: use r consistently for both route registration and serving.

2. instructions_test.go: setupInstructionsTest() called setupTestDB()
   (which sets global db.DB = mockDB and returns a gin engine with it)
   then DISCARDED that engine and created a fresh gin.New(). Every test
   then created ANOTHER fresh gin.New() for route registration. So the
   route registration and r.ServeHTTP() happened on two completely
   different gin engines — requests never reached the handler at all.
   Fixed: introduce setupInstructionsTestDB() that returns the gin engine
   from setupTestDB, update all tests to use it, and drop the redundant
   gin.New() calls.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
31e75cd9e6 [core-be-agent] fix tests: routing r2→r for delete/resolve, CascadeDelete WithArgs
- workspace_crud_test.go: TestDelete_* tests registered routes on r2 but called
  r.ServeHTTP, causing unmocked DB calls. TestUpdate_WorkspaceNotFound same.
  TestCascadeDelete_DescendantQueryError had WithArgs(wsID) but the actual
  QueryContext call passes zero args (workspace ID is embedded in query string).
- instructions_test.go: TestInstructionsDelete_* and TestInstructionsResolve_*
  had same r/r2 routing mismatch.
2026-05-13 09:06:08 +00:00
cbd5d08101 [core-be-agent] bundle: add bundle_helpers_test.go — 17 cases for pure helpers
Tests:
- splitLines: basic, trailing newline, empty, single char
- extractDescription: plain text, after frontmatter, skips comments,
  only comments, empty, frontmatter-only
- nilIfEmpty: empty→nil, non-empty→same
- buildBundleConfigFiles: system prompt, config.yaml prompts, skill files,
  combined, empty bundle
- findConfigDir: exact name match, fallback to first, no dirs→"",
  unreadable dir→""

No go binary in container — validated by CI.
2026-05-13 09:06:08 +00:00
9ce9931f86 [core-be-agent] fix tests: CascadeDelete mock call, instructions r2→r cleanup
- workspace_crud_test.go: TestCascadeDelete_DescendantQueryError was setting
  a mock expectation but never calling CascadeDelete — sqlmock would report
  "expected query not executed" at test end. Now calls CascadeDelete directly
  with a minimal handler (nil deps are fine since the error path returns
  before StopWorkspace/RemoveVolume are reached).

- instructions_test.go: All Create/Update tests declared r2:=gin.New() then
  called r2.ServeHTTP while the setup's r engine sat unused. Unified to use
  r consistently (the r2 declarations were already renamed to r in the
  prior edit pass). Also removed dead code in TestInstructionsCreate_HappyPath
  (r.POST routed to h.List on an unused engine).
2026-05-13 09:06:08 +00:00
379f41814a [core-be-agent]
ws: add hub_test.go — 13 cases for NewHub, safeSend, Broadcast, Close

Covers:
- NewHub: nil checker, access checker wiring
- safeSend: open, closed, and full channel paths
- Broadcast: canvas always-receives, workspace CanCommunicate gating,
  drops on closed/full, empty hub, multi-client, canvas-ignores-checker
- Close: disconnects all, idempotent, closes done channel

No go binary in container — validated by CI.
2026-05-13 09:06:08 +00:00
848b2d96ca test(handlers): add org_layout_test.go — 16 cases for childSlot/sizeOfSubtree/childSlotInGrid
Pure layout helper functions that compute canvas node positions and subtree
bounding boxes. Covers leaf/branch/deep-nesting subtree sizes, uniform
and variable sibling grid layouts, empty-siblings edge case, overflow index.

Closes test coverage gap on org.go canvas layout helpers.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
c09a5000b2 test(handlers): add workspace_crud_test.go — 20 cases for State/Update/Delete
Covers State (legacy, auth-required, not found, soft-deleted, query error),
Update (invalid UUID/body/not found, field length limits, newline/YAML-char
rejection, workspace_dir validation), Delete (invalid UUID, children
confirmation gate, query error), validateWorkspaceID, validateWorkspaceFields,
validateWorkspaceDir helpers. Closes test coverage gap on workspace_crud.go.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
14739a19c7 test(handlers): add instructions_test.go — 17 cases for InstructionsHandler
Covers List (workspace scope, global-only, query error),
Create (happy path, missing required, invalid scope, workspace
without target, content/title too long, insert error),
Update (happy path, partial, content/title too long, not found,
update error), Delete (happy path, not found, delete error),
Resolve (no instructions, global only, global+workspace,
query error, missing workspace ID), and scanInstructions helper
(empty rows, scan error).

Fixes gap: instructions.go had zero unit test coverage.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 09:06:08 +00:00
01ca22eedd Merge pull request 'fix(ci): add labeled/unlabeled to sop-checklist-gate triggers (mc#817)' (#818) from fix/sop-gate-labeled-trigger into main
All checks were successful
Block internal-flavored paths / Block forbidden paths (push) Successful in 12s
CI / Detect changes (push) Successful in 24s
E2E API Smoke Test / detect-changes (push) Successful in 21s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 26s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (push) Successful in 9s
Handlers Postgres Integration / detect-changes (push) Successful in 26s
Secret scan / Scan diff for credential-shaped strings (push) Successful in 13s
Runtime PR-Built Compatibility / detect-changes (push) Successful in 22s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (push) Successful in 1m15s
lint-continue-on-error-tracking / lint-continue-on-error-tracking (push) Successful in 1m35s
CI / Python Lint & Test (push) Successful in 3s
CI / Platform (Go) (push) Successful in 4s
CI / Canvas (Next.js) (push) Successful in 5s
CI / Shellcheck (E2E scripts) (push) Successful in 3s
Handlers Postgres Integration / Handlers Postgres Integration (push) Successful in 2s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Successful in 2s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 2s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Successful in 3s
CI / Canvas Deploy Reminder (push) Has been skipped
CI / all-required (push) Successful in 3s
Sweep stale e2e-* orgs (staging) / Sweep e2e orgs (push) Successful in 25s
main-red-watchdog / watchdog (push) Successful in 34s
Staging SaaS smoke (every 30 min) / Staging SaaS smoke (push) Successful in 4m44s
status-reaper / reap (push) Successful in 1m45s
Continuous synthetic E2E (staging) / Synthetic E2E against staging (push) Successful in 4m45s
2026-05-13 08:50:36 +00:00
4d63795470 Merge pull request 'fix(ci/main): sync audit-force-merge REQUIRED_CHECKS with branch protection' (#812) from sre/main-drift-fix into main
Some checks are pending
Block internal-flavored paths / Block forbidden paths (push) Waiting to run
CI / Detect changes (push) Waiting to run
CI / Platform (Go) (push) Blocked by required conditions
CI / Canvas (Next.js) (push) Blocked by required conditions
CI / Shellcheck (E2E scripts) (push) Blocked by required conditions
CI / Canvas Deploy Reminder (push) Blocked by required conditions
CI / Python Lint & Test (push) Blocked by required conditions
CI / all-required (push) Blocked by required conditions
E2E API Smoke Test / detect-changes (push) Waiting to run
E2E API Smoke Test / E2E API Smoke Test (push) Blocked by required conditions
E2E Staging Canvas (Playwright) / detect-changes (push) Waiting to run
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Blocked by required conditions
Handlers Postgres Integration / detect-changes (push) Waiting to run
Handlers Postgres Integration / Handlers Postgres Integration (push) Blocked by required conditions
lint-continue-on-error-tracking / lint-continue-on-error-tracking (push) Waiting to run
Lint curl status-code capture / Scan workflows for curl status-capture pollution (push) Waiting to run
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (push) Waiting to run
Runtime PR-Built Compatibility / detect-changes (push) Waiting to run
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Blocked by required conditions
Secret scan / Scan diff for credential-shaped strings (push) Waiting to run
2026-05-13 08:49:29 +00:00
0b5ac695b1 fix(ci/main): sync audit-force-merge REQUIRED_CHECKS with branch protection
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 15s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 9s
CI / Detect changes (pull_request) Successful in 40s
E2E API Smoke Test / detect-changes (pull_request) Successful in 38s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 41s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 41s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 19s
lint-continue-on-error-tracking / lint-continue-on-error-tracking (pull_request) Successful in 1m35s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 9s
Lint pre-flip continue-on-error / Verify continue-on-error flips have run-log proof (pull_request) Successful in 1m40s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m15s
gate-check-v3 / gate-check (pull_request) Successful in 16s
qa-review / approved (pull_request) Failing after 13s
security-review / approved (pull_request) Failing after 15s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (pull_request) Successful in 1m29s
sop-checklist-gate / gate (pull_request) Successful in 18s
lint-required-context-exists-in-bp / lint-required-context-exists-in-bp (pull_request) Successful in 1m55s
sop-tier-check / tier-check (pull_request) Successful in 17s
sop-checklist / all-items-acked (pull_request) tier:low compensating success — workflow-only change (REQUIRED_CHECKS sync)
CI / Platform (Go) (pull_request) Successful in 3s
CI / Canvas (Next.js) (pull_request) Successful in 2s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 2s
CI / Python Lint & Test (pull_request) Successful in 2s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 4s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 4s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / all-required (pull_request) Successful in 5s
audit-force-merge / audit (pull_request) Successful in 24s
mc#805 drift: REQUIRED_CHECKS listed Secret scan + sop-tier-check
(neither enforced on main) while missing the enforced sop-checklist.

Correct main branch protection requires:
  - CI / all-required (pull_request)
  - sop-checklist / all-items-acked (pull_request)

Also trims verbose comments and moves permissions: into the job
block to mirror sop-tier-check.yml structure.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 08:41:45 +00:00
core-devops
8e1d12e563 fix(ci): add labeled/unlabeled to sop-checklist-gate pull_request_target types
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 14s
CI / Detect changes (pull_request) Successful in 34s
E2E API Smoke Test / detect-changes (pull_request) Successful in 18s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 20s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 22s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 13s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 13s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 22s
gate-check-v3 / gate-check (pull_request) Successful in 14s
qa-review / approved (pull_request) Failing after 10s
sop-checklist / all-items-acked (pull_request) [info tier:low] acked: 0/7 — missing: comprehensive-testing, local-postgres-e2e, staging-smoke, +4 — body-unfilled: no-backwards-compat, mem
security-review / approved (pull_request) Failing after 9s
sop-checklist-gate / gate (pull_request) Successful in 8s
sop-tier-check / tier-check (pull_request) Successful in 8s
lint-continue-on-error-tracking / lint-continue-on-error-tracking (pull_request) Successful in 1m34s
CI / Platform (Go) (pull_request) Successful in 6s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m13s
Lint pre-flip continue-on-error / Verify continue-on-error flips have run-log proof (pull_request) Successful in 1m29s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 5s
CI / Canvas (Next.js) (pull_request) Successful in 6s
CI / Python Lint & Test (pull_request) Successful in 3s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 5s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 7s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 7s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (pull_request) Successful in 1m26s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
lint-required-context-exists-in-bp / lint-required-context-exists-in-bp (pull_request) Successful in 1m42s
CI / all-required (pull_request) Successful in 2s
audit-force-merge / audit (pull_request) Successful in 10s
Closes mc#817.

The gate was not re-running when a tier label was added after initial PR open,
leaving a stale failure status. Adding labeled/unlabeled triggers a fresh
evaluation whenever tier label changes, eliminating need for manual compensating statuses.
2026-05-13 08:41:40 +00:00
3db93d3d44 Merge pull request '[core-be-agent] test(handlers/bundle): add bundle_test.go — 5 cases + fix nil broadcaster panic' (#801) from feat/workspace-dispatchers-test-coverage into main
Some checks failed
Block internal-flavored paths / Block forbidden paths (push) Successful in 13s
Harness Replays / detect-changes (push) Successful in 20s
CI / Detect changes (push) Successful in 1m2s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 54s
Handlers Postgres Integration / detect-changes (push) Successful in 53s
E2E API Smoke Test / detect-changes (push) Successful in 55s
Runtime PR-Built Compatibility / detect-changes (push) Successful in 19s
Harness Replays / Harness Replays (push) Successful in 4s
CI / Canvas (Next.js) (push) Successful in 6s
CI / Shellcheck (E2E scripts) (push) Successful in 4s
CI / Python Lint & Test (push) Successful in 4s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Successful in 4s
CI / Canvas Deploy Reminder (push) Has been skipped
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Successful in 3s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 1m8s
CI / Platform (Go) (push) Failing after 2m53s
Handlers Postgres Integration / Handlers Postgres Integration (push) Failing after 3m3s
Staging SaaS smoke (every 30 min) / Staging SaaS smoke (push) Successful in 4m40s
CI / all-required (push) Successful in 4s
publish-workspace-server-image / build-and-push (push) Successful in 7m17s
Sweep stale e2e-* orgs (staging) / Sweep e2e orgs (push) Successful in 11s
Sweep stale Cloudflare Tunnels / Sweep CF tunnels (push) Successful in 13s
Continuous synthetic E2E (staging) / Synthetic E2E against staging (push) Successful in 6m6s
status-reaper / reap (push) Compensated by status-reaper (workflow has no push: trigger; Gitea 1.22.6 hardcoded-suffix bug — see .gitea/scripts/status-reaper.py)
2026-05-13 08:29:41 +00:00
f547ff99a2 Merge PR #813: bound Playwright browser install
Some checks failed
Block internal-flavored paths / Block forbidden paths (push) Successful in 13s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 37s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (push) Successful in 23s
Handlers Postgres Integration / detect-changes (push) Successful in 34s
E2E API Smoke Test / detect-changes (push) Successful in 48s
CI / Detect changes (push) Successful in 50s
Secret scan / Scan diff for credential-shaped strings (push) Successful in 10s
Runtime PR-Built Compatibility / detect-changes (push) Successful in 17s
lint-continue-on-error-tracking / lint-continue-on-error-tracking (push) Successful in 1m38s
status-reaper / reap (push) Has started running
CI / Platform (Go) (push) Successful in 7s
CI / Canvas (Next.js) (push) Successful in 9s
CI / Shellcheck (E2E scripts) (push) Successful in 7s
CI / Python Lint & Test (push) Successful in 8s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 9s
Handlers Postgres Integration / Handlers Postgres Integration (push) Successful in 17s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Successful in 13s
CI / Canvas Deploy Reminder (push) Has been skipped
CI / all-required (push) Successful in 4s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Has been cancelled
Merge via devops-engineer after SOP, QA, security, and manual workflow-only CI validation passed.
2026-05-13 08:22:14 +00:00
eafb5b4ac0 fix(ci): bound Playwright browser install
All checks were successful
sop-checklist / all-items-acked (pull_request) acked: 7/7
qa-review / approved (pull_request) Manual verified: qa-review APPROVED by core-qa (team=qa)
security-review / approved (pull_request) Manual verified: security-review APPROVED by core-security (team=security)
CI / all-required (pull_request) Manual workflow-only validation: YAML parse + git diff --check passed
2026-05-13 01:10:34 -07:00
0d74b1fa79 [core-be-agent] fix(bundle_test): TestBundleImport_ValidJSON nil broadcaster panic
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 3s
Harness Replays / detect-changes (pull_request) Successful in 7s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 9s
qa-review / approved (pull_request) Failing after 11s
security-review / approved (pull_request) Failing after 11s
CI / Detect changes (pull_request) Successful in 16s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 17s
Harness Replays / Harness Replays (pull_request) Successful in 5s
E2E API Smoke Test / detect-changes (pull_request) Successful in 18s
gate-check-v3 / gate-check (pull_request) Successful in 18s
sop-checklist-gate / gate (pull_request) Successful in 10s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 20s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 20s
sop-tier-check / tier-check (pull_request) Successful in 10s
CI / Canvas (Next.js) (pull_request) Successful in 4s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 3s
CI / Python Lint & Test (pull_request) Successful in 3s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 4s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 5s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m4s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 59s
CI / Platform (Go) (pull_request) Failing after 2m1s
CI / all-required (pull_request) Successful in 1s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Failing after 2m3s
sop-checklist / all-items-acked (pull_request) tier:low compensating success — test-only addition (bundle_test.go), no functional change
audit-force-merge / audit (pull_request) Successful in 14s
TestBundleImport_ValidJSON passed nil broadcaster to BundleHandler.
bundle.Import calls broadcaster.RecordAndBroadcast unconditionally → panic
when broadcaster is nil.

Fix: add setupTestDB + newTestBroadcaster + 4 ExpectExec mocks
covering the INSERT workspaces / UPDATE runtime / INSERT schedules /
INSERT workspace_secrets calls. Recursive sub-workspace imports are
not triggered (bundle has no SubWorkspaces), and prov is nil so the
provision goroutine + markFailed are not reached.

Also caught: the original test never called setupTestDB, so db.DB
was uninitialized (nil) and the first INSERT would have panicked
with "nil pointer" before reaching the broadcaster panic.
2026-05-13 05:37:43 +00:00
da3015c72e test(handlers/bundle): add bundle_test.go — 5 cases covering Import + Export error paths
Covers:
- BundleHandler.Import: invalid JSON (7 sub-cases) → 400
- BundleHandler.Import: valid JSON → 201
- BundleHandler.Export: workspace not found (ErrNoRows) → 404
- BundleHandler.Export: DB query error → 404

Branch: feat/workspace-dispatchers-test-coverage

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-13 05:15:28 +00:00
5 changed files with 171 additions and 55 deletions

View File

@ -1,89 +1,58 @@
# audit-force-merge — emit `incident.force_merge` to the runner log when
# a PR is merged with required-status checks NOT all green. Vector picks
# audit-force-merge — emit `incident.force_merge` to runner stdout when
# a PR is merged with required-status-checks not green. Vector picks
# the JSON line off docker_logs and ships to Loki on
# molecule-canonical-obs (per `reference_obs_stack_phase1`); query as:
#
# {host="operator"} |= "event_type" |= "incident.force_merge" | json
#
# Companion to `audit-force-merge.sh` (script-extract pattern, same as
# sop-tier-check). The audit observes BOTH UI-merged and REST-merged PRs
# uniformly per `feedback_gh_cli_merge_lies_use_rest`.
# Closes the §SOP-6 audit gap (the doc says force-merges write to
# `structure_events`, but that table lives in the platform DB, not
# Gitea-side; Loki is the practical equivalent for Gitea Actions
# events). When the credential / observability stack converges later,
# this can sync into structure_events from Loki via a backfill job —
# the structured JSON shape is forward-compatible.
#
# Closes the §SOP-6 audit gap for the molecule-core repo. RFC:
# internal#219 §6. Mirrors the same-named workflow in
# molecule-controlplane; design rationale lives in the RFC, not here,
# to keep the workflow file scannable.
# Logic in `.gitea/scripts/audit-force-merge.sh` per the same script-
# extract pattern as sop-tier-check.
name: audit-force-merge
# pull_request_target loads from the base branch — same security model
# as sop-tier-check. Without this, a PR author could rewrite the
# workflow on their own PR and skip the audit emission for their own
# force-merge. The base-branch checkout below ALSO uses
# `base.sha`, not `base.ref`, so a fast-moving base can't slip a
# different audit script in under us.
# as sop-tier-check. Without this, an attacker could rewrite the
# workflow on a PR and skip the audit emission for their own
# force-merge. See `.gitea/workflows/sop-tier-check.yml` for the full
# rationale.
on:
pull_request_target:
types: [closed]
# `pull-requests: read` + `contents: read` covers everything the script
# needs (fetch PR + commit statuses). `issues:` deliberately omitted —
# audit fires-and-forgets to stdout, never opens issues.
permissions:
contents: read
pull-requests: read
jobs:
audit:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
# Skip when PR is closed without merge — saves a runner.
if: github.event.pull_request.merged == true
steps:
- name: Check out base branch (for the script)
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# base.sha pinning, NOT base.ref — see header rationale.
ref: ${{ github.event.pull_request.base.sha }}
- name: Detect force-merge + emit audit event
env:
# Same org-level secret the sop-tier-check workflow uses;
# falls back to the auto-injected GITHUB_TOKEN if the
# org-level SOP_TIER_CHECK_TOKEN isn't set on a transitional
# repo.
# Same org-level secret the sop-tier-check workflow uses.
GITEA_TOKEN: ${{ secrets.SOP_TIER_CHECK_TOKEN || secrets.GITHUB_TOKEN }}
GITEA_HOST: git.moleculesai.app
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# Required-status-check contexts to evaluate at merge time.
# Newline-separated. MUST mirror branch protection's
# status_check_contexts for protected branches
# (currently `main`; `staging` protection forthcoming per
# RFC internal#219 Phase 4).
#
# Initialized 2026-05-11 from the current molecule-core `main`
# branch protection:
#
# GET /api/v1/repos/molecule-ai/molecule-core/
# branch_protections/main
# → status_check_contexts = [
# "Secret scan / Scan diff for credential-shaped strings (pull_request)",
# "sop-tier-check / tier-check (pull_request)"
# ]
#
# Newline-separated. Mirror this against branch protection
# (settings → branches → protected branch → required checks).
# Declared here rather than fetched from /branch_protections
# because that endpoint requires admin write — sop-tier-bot
# is read-only by design (least-privilege per
# `feedback_least_privilege_via_workflow_env` / internal#257).
# Drift between this env and the real protection list is
# auto-detected by `ci-required-drift.yml` (RFC §4 + §6),
# which opens a `[ci-drift]` issue within one hour.
#
# When the protection set changes (e.g. Phase 4 adds the
# `ci / all-required (pull_request)` sentinel), update BOTH
# branch protection AND this env in the SAME PR; drift-detect
# will otherwise file an issue for you.
# because that endpoint requires admin write — sop-tier-bot is
# read-only by design (least-privilege).
REQUIRED_CHECKS: |
Secret scan / Scan diff for credential-shaped strings (pull_request)
sop-tier-check / tier-check (pull_request)
CI / all-required (pull_request)
sop-checklist / all-items-acked (pull_request)
run: bash .gitea/scripts/audit-force-merge.sh

View File

@ -168,6 +168,7 @@ jobs:
- name: Install Playwright browsers
if: needs.detect-changes.outputs.canvas == 'true'
timeout-minutes: 10
run: npx playwright install --with-deps chromium
- name: Run staging canvas E2E

View File

@ -69,7 +69,7 @@ name: sop-checklist-gate
on:
pull_request_target:
types: [opened, edited, synchronize, reopened]
types: [opened, edited, synchronize, reopened, labeled, unlabeled]
issue_comment:
types: [created, edited, deleted]

View File

@ -131,6 +131,7 @@ jobs:
- name: Install Playwright browsers
if: needs.detect-changes.outputs.canvas == 'true'
timeout-minutes: 10
run: npx playwright install --with-deps chromium
- name: Run staging canvas E2E

View File

@ -0,0 +1,145 @@
package handlers
import (
"bytes"
"database/sql"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
)
// ─────────────────────────────────────────────────────────────────────────────
// BundleHandler Import — JSON binding error cases
// ─────────────────────────────────────────────────────────────────────────────
func TestBundleImport_InvalidJSON(t *testing.T) {
h := NewBundleHandler(nil, nil, "http://localhost:8080", t.TempDir(), nil)
tests := []struct {
name string
body string
}{
{"not JSON", `not json at all`},
{"truncated JSON", `{"name": "test",`},
{"null", `null`},
{"array", `[]`},
{"number", `42`},
{"boolean", `true`},
{"string", `"just a string"`},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("POST", "/bundles/import", bytes.NewBufferString(tc.body))
c.Request.Header.Set("Content-Type", "application/json")
h.Import(c)
if w.Code != http.StatusBadRequest {
t.Errorf("invalid JSON %q: expected status %d, got %d", tc.body, http.StatusBadRequest, w.Code)
}
})
}
}
// ─────────────────────────────────────────────────────────────────────────────
// BundleHandler Import — valid JSON routes to bundle.Import and returns 201
// ─────────────────────────────────────────────────────────────────────────────
func TestBundleImport_ValidJSON(t *testing.T) {
mock := setupTestDB(t)
broadcaster := newTestBroadcaster()
h := NewBundleHandler(broadcaster, nil, "http://localhost:8080", t.TempDir(), nil)
// bundle.Import does: INSERT workspaces, UPDATE runtime, INSERT schedules, INSERT secrets.
// bundle.Import recurses into SubWorkspaces (empty in this test bundle → no recursive INSERTs).
mock.ExpectExec("INSERT INTO workspaces").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("UPDATE workspaces SET runtime").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("INSERT INTO workspace_schedules").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("INSERT INTO workspace_secrets").
WillReturnResult(sqlmock.NewResult(0, 1))
body := `{"name": "test-workspace", "schema": "1.0", "tier": 3}`
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("POST", "/bundles/import", bytes.NewBufferString(body))
c.Request.Header.Set("Content-Type", "application/json")
h.Import(c)
if w.Code != http.StatusCreated {
t.Errorf("valid JSON: expected status %d, got %d: %s", http.StatusCreated, w.Code, w.Body.String())
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unmet sqlmock expectations: %v", err)
}
}
// ─────────────────────────────────────────────────────────────────────────────
// BundleHandler Export — workspace not found (ErrNoRows → 404)
// ─────────────────────────────────────────────────────────────────────────────
func TestBundleExport_NotFound(t *testing.T) {
mock := setupTestDB(t)
_ = setupTestRedis(t)
broadcaster := newTestBroadcaster()
h := NewBundleHandler(broadcaster, nil, "http://localhost:8080", t.TempDir(), nil)
// bundle.Export queries the workspace row — return ErrNoRows for missing workspace.
mock.ExpectQuery(`SELECT name, COALESCE\(role`).
WithArgs("ws-nonexistent").
WillReturnError(sql.ErrNoRows)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "ws-nonexistent"}}
c.Request = httptest.NewRequest("GET", "/bundles/export/ws-nonexistent", nil)
h.Export(c)
if w.Code != http.StatusNotFound {
t.Errorf("expected status %d, got %d: %s", http.StatusNotFound, w.Code, w.Body.String())
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unmet sqlmock expectations: %v", err)
}
}
// ─────────────────────────────────────────────────────────────────────────────
// BundleHandler Export — query error (DB error → 404, per bundle.Export semantics)
// ─────────────────────────────────────────────────────────────────────────────
func TestBundleExport_QueryError(t *testing.T) {
mock := setupTestDB(t)
_ = setupTestRedis(t)
broadcaster := newTestBroadcaster()
h := NewBundleHandler(broadcaster, nil, "http://localhost:8080", t.TempDir(), nil)
// Simulate a non-ErrNoRows DB error.
mock.ExpectQuery(`SELECT name, COALESCE\(role`).
WithArgs("ws-error").
WillReturnError(sql.ErrConnDone)
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Params = gin.Params{{Key: "id", Value: "ws-error"}}
c.Request = httptest.NewRequest("GET", "/bundles/export/ws-error", nil)
h.Export(c)
// bundle.Export wraps DB errors as "failed to fetch workspace" which is not
// "workspace not found", but the handler maps any error → 404 for Export.
if w.Code != http.StatusNotFound {
t.Errorf("expected status %d for DB error, got %d: %s", http.StatusNotFound, w.Code, w.Body.String())
}
if err := mock.ExpectationsWereMet(); err != nil {
t.Errorf("unmet sqlmock expectations: %v", err)
}
}