fix(test): persist API key + anchor rights selector + idempotent createUser #19

Merged
arcodange merged 1 commits from claude/sandbox-provision-run into main 2026-06-29 14:31:26 +02:00
Owner

First real run of provisionSandbox.ts against the seeded sandbox surfaced three bugs in userSetup.ts (verified live: ai_agent_sandbox rowid 4 had api_key NULL and was missing only facture/creer of the 11 intended rights):

  1. generateApiKey never saved. It generated the key client-side and read it into .ai_agent_sandbox.key, but never submitted the edit form, so Dolibarr never persisted api_key (DB stayed NULL → the key can't authenticate). → now clicks Save after generating.
  2. assignRights selector was a substring match. [href*="rights=12"] also matched rights=121 / rights=1232, so .first() clicked the wrong link and facture creer (12) was skipped. → anchored with the trailing & (rights=12&) for an exact match.
  3. createUser wasn't idempotent. A re-run hit the existing login and couldn't parse a new id. → added findUserId (look up by login in the user list) and return the existing id instead of creating a duplicate.

deno check passes. The fixes make a re-run complete the provisioning: it finds the existing user, grants the missing facture creer, and generates + persists the API key.

🤖 Generated with Claude Code

First real run of `provisionSandbox.ts` against the seeded sandbox surfaced three bugs in `userSetup.ts` (verified live: `ai_agent_sandbox` rowid 4 had `api_key` NULL and was missing only `facture/creer` of the 11 intended rights): 1. **`generateApiKey` never saved.** It generated the key client-side and read it into `.ai_agent_sandbox.key`, but never submitted the edit form, so Dolibarr never persisted `api_key` (DB stayed NULL → the key can't authenticate). → now clicks **Save** after generating. 2. **`assignRights` selector was a substring match.** `[href*="rights=12"]` also matched `rights=121` / `rights=1232`, so `.first()` clicked the wrong link and `facture creer` (12) was skipped. → anchored with the trailing `&` (`rights=12&`) for an exact match. 3. **`createUser` wasn't idempotent.** A re-run hit the existing login and couldn't parse a new id. → added `findUserId` (look up by login in the user list) and return the existing id instead of creating a duplicate. `deno check` passes. The fixes make a re-run complete the provisioning: it finds the existing user, grants the missing `facture creer`, and generates + **persists** the API key. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
arcodange added 1 commit 2026-06-29 14:31:11 +02:00
First real run against the sandbox revealed three issues in userSetup.ts:

1. generateApiKey generated the key client-side and read it into the file but
   never submitted the edit form, so Dolibarr never persisted api_key (DB stayed
   NULL → the key could not authenticate). Now it clicks Save after generating.

2. assignRights matched `rights=<id>` as an href substring, so a short id like
   12 (facture creer) also matched rights=121 / rights=1232 and .first() clicked
   the wrong link — facture creer was never granted. Anchored with a trailing
   "&" (rights=<id>&) for an exact match.

3. createUser was not idempotent: a re-run hit the existing login and failed to
   parse a new id. Added findUserId (look up by login via the user list) and
   return the existing id instead of creating a duplicate.

Verified the symptoms live: ai_agent_sandbox (rowid 4) had api_key NULL and was
missing only facture/creer among the 11 intended rights.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
arcodange merged commit 37865c55c5 into main 2026-06-29 14:31:26 +02:00
arcodange deleted branch claude/sandbox-provision-run 2026-06-29 14:31:26 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: arcodange-org/erp#19