Merge pull request 'fix(handlers): repair current main test blockers' (#900) from fix/core-main-handlers-hotfix into main
Some checks failed
Block internal-flavored paths / Block forbidden paths (push) Successful in 12s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 26s
CI / Detect changes (pull_request) Successful in 29s
CI / Detect changes (push) Successful in 19s
E2E API Smoke Test / detect-changes (pull_request) Successful in 22s
E2E API Smoke Test / detect-changes (push) Successful in 24s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 27s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 33s
Harness Replays / detect-changes (pull_request) Successful in 35s
Harness Replays / detect-changes (push) Successful in 19s
Handlers Postgres Integration / detect-changes (push) Successful in 44s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 18s
Runtime PR-Built Compatibility / detect-changes (push) Successful in 41s
publish-runtime-autobump / bump-and-tag (pull_request) Has been skipped
lint-continue-on-error-tracking / lint-continue-on-error-tracking (pull_request) Successful in 2m6s
review-check-tests / review-check.sh regression tests (pull_request) Successful in 20s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 40s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 37s
gate-check-v3 / gate-check (pull_request) Successful in 39s
lint-mask-pr-atomicity / lint-mask-pr-atomicity (pull_request) Successful in 2m4s
qa-review / approved (pull_request) Successful in 26s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m20s
publish-runtime-autobump / pr-validate (pull_request) Successful in 56s
Lint pre-flip continue-on-error / Verify continue-on-error flips have run-log proof (pull_request) Successful in 2m5s
lint-required-context-exists-in-bp / lint-required-context-exists-in-bp (pull_request) Failing after 1m53s
security-review / approved (pull_request) Successful in 29s
sop-checklist-gate / gate (pull_request) Successful in 31s
sop-tier-check / tier-check (pull_request) Successful in 29s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (pull_request) Failing after 1m28s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Successful in 1m38s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 28s
CI / Shellcheck (E2E scripts) (push) Successful in 9s
CI / Canvas (Next.js) (push) Successful in 14s
CI / Python Lint & Test (push) Successful in 11s
publish-workspace-server-image / build-and-push (push) Successful in 9m43s
Harness Replays / Harness Replays (pull_request) Successful in 14s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Successful in 19s
Harness Replays / Harness Replays (push) Successful in 15s
audit-force-merge / audit (pull_request) Has been skipped
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 3m17s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 3m26s
main-red-watchdog / watchdog (push) Successful in 2m32s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Successful in 10s
CI / Python Lint & Test (pull_request) Successful in 8m0s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6m54s
Handlers Postgres Integration / Handlers Postgres Integration (push) Successful in 6m48s
gate-check-v3 / gate-check (push) Successful in 46s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2m30s
CI / Canvas Deploy Reminder (push) Has been skipped
publish-workspace-server-image / Production auto-deploy (push) Failing after 23s
Sweep stale Cloudflare DNS records / Sweep CF orphans (push) Successful in 24s
ci-required-drift / drift (push) Successful in 1m13s
CI / Canvas (Next.js) (pull_request) Successful in 16m56s
CI / Platform (Go) (pull_request) Successful in 18m17s
CI / Platform (Go) (push) Successful in 17m48s
Sweep stale e2e-* orgs (staging) / Sweep e2e orgs (push) Successful in 28s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / all-required (pull_request) Successful in 6s
CI / all-required (push) Successful in 4s
Staging SaaS smoke (every 30 min) / Staging SaaS smoke (push) Successful in 5m3s
status-reaper / reap (push) Has started running
gitea-merge-queue / queue (push) Successful in 26s
Continuous synthetic E2E (staging) / Synthetic E2E against staging (push) Successful in 4m54s
Some checks failed
Block internal-flavored paths / Block forbidden paths (push) Successful in 12s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 26s
CI / Detect changes (pull_request) Successful in 29s
CI / Detect changes (push) Successful in 19s
E2E API Smoke Test / detect-changes (pull_request) Successful in 22s
E2E API Smoke Test / detect-changes (push) Successful in 24s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 27s
E2E Staging Canvas (Playwright) / detect-changes (push) Successful in 33s
Harness Replays / detect-changes (pull_request) Successful in 35s
Harness Replays / detect-changes (push) Successful in 19s
Handlers Postgres Integration / detect-changes (push) Successful in 44s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 18s
Runtime PR-Built Compatibility / detect-changes (push) Successful in 41s
publish-runtime-autobump / bump-and-tag (pull_request) Has been skipped
lint-continue-on-error-tracking / lint-continue-on-error-tracking (pull_request) Successful in 2m6s
review-check-tests / review-check.sh regression tests (pull_request) Successful in 20s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 40s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 37s
gate-check-v3 / gate-check (pull_request) Successful in 39s
lint-mask-pr-atomicity / lint-mask-pr-atomicity (pull_request) Successful in 2m4s
qa-review / approved (pull_request) Successful in 26s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 1m20s
publish-runtime-autobump / pr-validate (pull_request) Successful in 56s
Lint pre-flip continue-on-error / Verify continue-on-error flips have run-log proof (pull_request) Successful in 2m5s
lint-required-context-exists-in-bp / lint-required-context-exists-in-bp (pull_request) Failing after 1m53s
security-review / approved (pull_request) Successful in 29s
sop-checklist-gate / gate (pull_request) Successful in 31s
sop-tier-check / tier-check (pull_request) Successful in 29s
Lint workflow YAML (Gitea-1.22.6-hostile shapes) / Lint workflow YAML for Gitea-1.22.6-hostile shapes (pull_request) Failing after 1m28s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Successful in 1m38s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 28s
CI / Shellcheck (E2E scripts) (push) Successful in 9s
CI / Canvas (Next.js) (push) Successful in 14s
CI / Python Lint & Test (push) Successful in 11s
publish-workspace-server-image / build-and-push (push) Successful in 9m43s
Harness Replays / Harness Replays (pull_request) Successful in 14s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (push) Successful in 19s
Harness Replays / Harness Replays (push) Successful in 15s
audit-force-merge / audit (pull_request) Has been skipped
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 3m17s
E2E API Smoke Test / E2E API Smoke Test (push) Successful in 3m26s
main-red-watchdog / watchdog (push) Successful in 2m32s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (push) Successful in 10s
CI / Python Lint & Test (pull_request) Successful in 8m0s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6m54s
Handlers Postgres Integration / Handlers Postgres Integration (push) Successful in 6m48s
gate-check-v3 / gate-check (push) Successful in 46s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2m30s
CI / Canvas Deploy Reminder (push) Has been skipped
publish-workspace-server-image / Production auto-deploy (push) Failing after 23s
Sweep stale Cloudflare DNS records / Sweep CF orphans (push) Successful in 24s
ci-required-drift / drift (push) Successful in 1m13s
CI / Canvas (Next.js) (pull_request) Successful in 16m56s
CI / Platform (Go) (pull_request) Successful in 18m17s
CI / Platform (Go) (push) Successful in 17m48s
Sweep stale e2e-* orgs (staging) / Sweep e2e orgs (push) Successful in 28s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / all-required (pull_request) Successful in 6s
CI / all-required (push) Successful in 4s
Staging SaaS smoke (every 30 min) / Staging SaaS smoke (push) Successful in 5m3s
status-reaper / reap (push) Has started running
gitea-merge-queue / queue (push) Successful in 26s
Continuous synthetic E2E (staging) / Synthetic E2E against staging (push) Successful in 4m54s
This commit is contained in:
commit
4c2172a0f0
@ -57,16 +57,23 @@ func extractIdempotencyKey(body []byte) string {
|
||||
func extractExpiresInSeconds(body []byte) int {
|
||||
var envelope struct {
|
||||
Params struct {
|
||||
ExpiresInSeconds int `json:"expires_in_seconds"`
|
||||
ExpiresInSeconds interface{} `json:"expires_in_seconds"`
|
||||
} `json:"params"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &envelope); err != nil {
|
||||
return 0
|
||||
}
|
||||
if envelope.Params.ExpiresInSeconds < 0 {
|
||||
var seconds int
|
||||
switch v := envelope.Params.ExpiresInSeconds.(type) {
|
||||
case float64:
|
||||
seconds = int(v)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return envelope.Params.ExpiresInSeconds
|
||||
if seconds < 0 {
|
||||
return 0
|
||||
}
|
||||
return seconds
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@ -282,6 +282,7 @@ func TestListDelegations_WithResults(t *testing.T) {
|
||||
dh := NewDelegationHandler(wh, broadcaster)
|
||||
|
||||
now := time.Now()
|
||||
deadline := now.Add(6 * time.Hour)
|
||||
// Ledger query returns rows — no fallback to activity_logs
|
||||
rows := sqlmock.NewRows([]string{
|
||||
"delegation_id", "caller_id", "callee_id", "task_preview",
|
||||
@ -290,10 +291,10 @@ func TestListDelegations_WithResults(t *testing.T) {
|
||||
}).
|
||||
AddRow("del-111", "ws-source", "ws-target",
|
||||
"Delegating to ws-target", "pending", "", "",
|
||||
&now, &now.Add(6*time.Hour), now, now).
|
||||
&now, &deadline, now, now).
|
||||
AddRow("del-222", "ws-source", "ws-target",
|
||||
"Delegation completed (hello world)", "completed", "hello world", "",
|
||||
&now, &now.Add(6*time.Hour), now, now.Add(time.Minute))
|
||||
&now, &deadline, now, now.Add(time.Minute))
|
||||
|
||||
mock.ExpectQuery("SELECT d.delegation_id, d.caller_id, d.callee_id, d.task_preview").
|
||||
WithArgs("ws-source").
|
||||
@ -1360,6 +1361,7 @@ func TestExtractResponseText_EmptyText(t *testing.T) {
|
||||
got := extractResponseText(body)
|
||||
if got != "" {
|
||||
t.Errorf("empty text: got %q, want %q", got, "")
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- ListDelegations: ledger has rows → returns them (no activity_logs fallback) ----------
|
||||
@ -1372,6 +1374,7 @@ func TestListDelegations_LedgerRowsReturned(t *testing.T) {
|
||||
dh := NewDelegationHandler(wh, broadcaster)
|
||||
|
||||
now := time.Now()
|
||||
deadline := now.Add(6 * time.Hour)
|
||||
// Ledger query returns rows
|
||||
ledgerRows := sqlmock.NewRows([]string{
|
||||
"delegation_id", "caller_id", "callee_id", "task_preview",
|
||||
@ -1380,7 +1383,7 @@ func TestListDelegations_LedgerRowsReturned(t *testing.T) {
|
||||
}).AddRow(
|
||||
"del-ledger-001", "caller-uuid", "callee-uuid",
|
||||
"Analyze the codebase for bugs", "in_progress", "", "",
|
||||
&now, &now.Add(6*time.Hour), now, now,
|
||||
&now, &deadline, now, now,
|
||||
)
|
||||
mock.ExpectQuery("SELECT d.delegation_id, d.caller_id, d.callee_id, d.task_preview").
|
||||
WithArgs("caller-uuid").
|
||||
@ -1591,6 +1594,7 @@ func TestListDelegations_LedgerCompletedIncludesResultPreview(t *testing.T) {
|
||||
dh := NewDelegationHandler(wh, broadcaster)
|
||||
|
||||
now := time.Now()
|
||||
deadline := now.Add(6 * time.Hour)
|
||||
ledgerRows := sqlmock.NewRows([]string{
|
||||
"delegation_id", "caller_id", "callee_id", "task_preview",
|
||||
"status", "result_preview", "error_detail", "last_heartbeat",
|
||||
@ -1598,7 +1602,7 @@ func TestListDelegations_LedgerCompletedIncludesResultPreview(t *testing.T) {
|
||||
}).AddRow(
|
||||
"del-complete-001", "caller-uuid", "callee-uuid",
|
||||
"Run analysis", "completed", "Analysis complete: 42 issues found", "",
|
||||
&now, &now.Add(6*time.Hour), now, now,
|
||||
&now, &deadline, now, now,
|
||||
)
|
||||
mock.ExpectQuery("SELECT d.delegation_id, d.caller_id, d.callee_id, d.task_preview").
|
||||
WithArgs("caller-uuid").
|
||||
@ -1645,6 +1649,7 @@ func TestListDelegations_LedgerFailedIncludesErrorDetail(t *testing.T) {
|
||||
dh := NewDelegationHandler(wh, broadcaster)
|
||||
|
||||
now := time.Now()
|
||||
deadline := now.Add(6 * time.Hour)
|
||||
ledgerRows := sqlmock.NewRows([]string{
|
||||
"delegation_id", "caller_id", "callee_id", "task_preview",
|
||||
"status", "result_preview", "error_detail", "last_heartbeat",
|
||||
@ -1652,7 +1657,7 @@ func TestListDelegations_LedgerFailedIncludesErrorDetail(t *testing.T) {
|
||||
}).AddRow(
|
||||
"del-failed-001", "caller-uuid", "callee-uuid",
|
||||
"Fetch data", "failed", "", "Callee workspace not reachable",
|
||||
&now, &now.Add(6*time.Hour), now, now,
|
||||
&now, &deadline, now, now,
|
||||
)
|
||||
mock.ExpectQuery("SELECT d.delegation_id, d.caller_id, d.callee_id, d.task_preview").
|
||||
WithArgs("caller-uuid").
|
||||
@ -1682,7 +1687,6 @@ func TestListDelegations_LedgerFailedIncludesErrorDetail(t *testing.T) {
|
||||
t.Errorf("expected error detail, got %v", resp[0]["error"])
|
||||
}
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("unmet sqlmock expectations: %v", err) (fix(delegations): ListDelegations falls back to delegations table before activity_logs)
|
||||
t.Errorf("unmet sqlmock expectations: %v", err)
|
||||
}
|
||||
}
|
||||
(fix(delegations): ListDelegations falls back to delegations table before activity_logs)
|
||||
|
||||
@ -140,6 +140,14 @@ func (h *WorkspaceHandler) Update(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
if wsDir, ok := body["workspace_dir"]; ok && wsDir != nil {
|
||||
if dirStr, isStr := wsDir.(string); isStr && dirStr != "" {
|
||||
if err := validateWorkspaceDir(dirStr); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid workspace directory"})
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx := c.Request.Context()
|
||||
|
||||
|
||||
@ -39,6 +39,11 @@ func newWorkspaceCrudHandler(t *testing.T) *WorkspaceHandler {
|
||||
return NewWorkspaceHandler(nil, nil, "", t.TempDir())
|
||||
}
|
||||
|
||||
func expectWorkspaceLiveTokenCount(mock sqlmock.Sqlmock, count int) {
|
||||
mock.ExpectQuery(`SELECT COUNT\(\*\) FROM workspace_auth_tokens`).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"count"}).AddRow(count))
|
||||
}
|
||||
|
||||
// ---------- State ----------
|
||||
|
||||
func TestState_LegacyWorkspaceNoLiveToken(t *testing.T) {
|
||||
@ -50,8 +55,7 @@ func TestState_LegacyWorkspaceNoLiveToken(t *testing.T) {
|
||||
|
||||
// No live token — legacy workspace, no auth required.
|
||||
// HasAnyLiveToken always runs first (queries workspace_auth_tokens).
|
||||
mock.ExpectQuery(`SELECT EXISTS\(SELECT 1 FROM workspace_auth_tokens`).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(false))
|
||||
expectWorkspaceLiveTokenCount(mock, 0)
|
||||
mock.ExpectQuery(`SELECT status FROM workspaces WHERE id = \$1`).
|
||||
WithArgs(wsID).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"status"}).AddRow("running"))
|
||||
@ -86,8 +90,7 @@ func TestState_HasLiveTokenMissingAuth(t *testing.T) {
|
||||
|
||||
wsID := "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
|
||||
|
||||
mock.ExpectQuery(`SELECT EXISTS\(SELECT 1 FROM workspace_auth_tokens`).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(true))
|
||||
expectWorkspaceLiveTokenCount(mock, 1)
|
||||
|
||||
req, _ := http.NewRequest("GET", "/workspaces/"+wsID+"/state", nil)
|
||||
// No Authorization header
|
||||
@ -106,8 +109,7 @@ func TestState_WorkspaceNotFound(t *testing.T) {
|
||||
|
||||
wsID := "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
|
||||
|
||||
mock.ExpectQuery(`SELECT EXISTS\(SELECT 1 FROM workspace_auth_tokens`).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(false))
|
||||
expectWorkspaceLiveTokenCount(mock, 0)
|
||||
mock.ExpectQuery(`SELECT status FROM workspaces WHERE id = \$1`).
|
||||
WithArgs(wsID).
|
||||
WillReturnError(sql.ErrNoRows)
|
||||
@ -136,8 +138,7 @@ func TestState_WorkspaceSoftDeleted(t *testing.T) {
|
||||
|
||||
wsID := "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
|
||||
|
||||
mock.ExpectQuery(`SELECT EXISTS\(SELECT 1 FROM workspace_auth_tokens`).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(false))
|
||||
expectWorkspaceLiveTokenCount(mock, 0)
|
||||
mock.ExpectQuery(`SELECT status FROM workspaces WHERE id = \$1`).
|
||||
WithArgs(wsID).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"status"}).AddRow("removed"))
|
||||
@ -169,8 +170,7 @@ func TestState_QueryError(t *testing.T) {
|
||||
|
||||
wsID := "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
|
||||
|
||||
mock.ExpectQuery(`SELECT EXISTS\(SELECT 1 FROM workspace_auth_tokens`).
|
||||
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(false))
|
||||
expectWorkspaceLiveTokenCount(mock, 0)
|
||||
mock.ExpectQuery(`SELECT status FROM workspaces WHERE id = \$1`).
|
||||
WithArgs(wsID).
|
||||
WillReturnError(sql.ErrConnDone)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user