From 8065d7ef031b5efaf51ca4a4525da9566092d104 Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Tue, 21 Apr 2026 04:20:47 -0700 Subject: [PATCH] fix(orgtoken): update Validate test mock to include org_id column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Validate now SELECTs id/prefix/org_id; the test mock row only had two columns, so the actual query against sqlmock errored with 'invalid or revoked org api token' at runtime (the row couldn't Scan). Add org_id to the mocked row and assert it propagates to the 4th return value. This is a test-only change — the production code path already had the third column selected; CI was the canary. Co-Authored-By: Claude Opus 4.7 (1M context) --- workspace-server/internal/orgtoken/tokens_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/workspace-server/internal/orgtoken/tokens_test.go b/workspace-server/internal/orgtoken/tokens_test.go index 984fcd3c..ee47b680 100644 --- a/workspace-server/internal/orgtoken/tokens_test.go +++ b/workspace-server/internal/orgtoken/tokens_test.go @@ -72,14 +72,14 @@ func TestValidate_HappyPath(t *testing.T) { plaintext := "known-plaintext-for-test" hash := sha256.Sum256([]byte(plaintext)) - mock.ExpectQuery(`SELECT id, prefix FROM org_api_tokens`). + mock.ExpectQuery(`SELECT id, prefix, org_id FROM org_api_tokens`). WithArgs(hash[:]). - WillReturnRows(sqlmock.NewRows([]string{"id", "prefix"}).AddRow("tok-live", "abcd1234")) + WillReturnRows(sqlmock.NewRows([]string{"id", "prefix", "org_id"}).AddRow("tok-live", "abcd1234", "org-happy")) mock.ExpectExec(`UPDATE org_api_tokens SET last_used_at`). WithArgs("tok-live"). WillReturnResult(sqlmock.NewResult(0, 1)) - id, prefix, _, err := Validate(context.Background(), db, plaintext) + id, prefix, orgID, err := Validate(context.Background(), db, plaintext) if err != nil { t.Fatalf("Validate: %v", err) } @@ -89,6 +89,9 @@ func TestValidate_HappyPath(t *testing.T) { if prefix != "abcd1234" { t.Errorf("prefix = %q, want abcd1234", prefix) } + if orgID != "org-happy" { + t.Errorf("orgID = %q, want org-happy", orgID) + } } func TestValidate_EmptyPlaintextRejected(t *testing.T) {