Skip to content

refactor: extract shared tool boilerplate in tools.ts (plan 018)#89

Open
DavertMik wants to merge 1 commit into
mainfrom
refactor/tools-boilerplate-consolidation
Open

refactor: extract shared tool boilerplate in tools.ts (plan 018)#89
DavertMik wants to merge 1 commit into
mainfrom
refactor/tools-boilerplate-consolidation

Conversation

@DavertMik

Copy link
Copy Markdown
Contributor

Plan 018 — Consolidate duplicated boilerplate in tools.ts

src/ai/tools.ts (the Tester's tool belt) is built from copy-paste. This extracts the shared shapes so each tool contains only what's tool-specific. Behavior-preserving.

Done

  • errorText(error) — replaces the 9 identical error instanceof Error ? error.toString() : 'Unknown error occurred' ternaries (banned by CLAUDE.md).
  • commitNote(activeNote, result, toolResult, action) — replaces the 9 screenshot-guard + commit pairs; a fix to one copy previously missed eight. (The form PASSED path's screenshot-then-branch was proven equivalent: !hasObservablePageChange ⟹ the aria/url guard is false.)
  • 3 conditional spreads ...(action.lastError && { error }) → plain if.
  • createIframeTools(explorer) — renamed from createSpecialContextTools(explorer, 'iframe'); deletes the unreachable context !== 'iframe' guard. Tester call site's banned conditional spread → plain if (isInsideIframe) Object.assign(...); exitIframe is unique so assigning last is equivalent.
  • createLearnExperienceTool({ experienceTracker, getState }) factory — removes Navigator's null as unknown as Researcher type-lie.
  • getVisitedStates routes through successToolResult, gaining the action field.
  • First unit tests for tools.ts (TEST-01) — validation paths + factories, no browser.

Deferred / coordinated

  • Step 4 (click/hover fallback-loop) — DEFERRED: click/hover are not pure clones (click screenshots on success + disambiguates; hover does neither); folding risks subtle change without a live browser.
  • Step 8 (disambiguateElements → Navigator) — DEFERRED (optional, high churn).
  • Step 6 (countAriaChangesutils/aria.ts) — handled by plan-015 PR refactor: simplify ActionResult loading and Diff API (plan 015) #87; not duplicated here.
  • currentActionResult alias — deferred (cosmetic; createAgentTools declares stateManager per-execute).

Verification

  • bun test tests/unit770 pass / 0 fail (+6 new).
  • bun test tests/integration/63 pass / 0 fail.
  • bun run lint → clean; tsc in touched files 4 → 3, no new errors.

🤖 Generated with Claude Code

Replace copy-pasted boilerplate in the Tester tool belt:
- errorText() replaces 9 identical `error instanceof Error ? ...` ternaries
  (banned by CLAUDE.md).
- commitNote() replaces 9 screenshot-guard+commit pairs — the "fix one, miss
  eight" hazard collapses to one definition.
- 3 `...(action.lastError && {...})` conditional spreads become plain ifs.
- createIframeTools() replaces createSpecialContextTools(explorer,'iframe');
  drop the unreachable `context !== 'iframe'` guard and the banned conditional
  spread at the tester call site (exitIframe key is unique — assigning last is
  equivalent).
- createLearnExperienceTool() factory removes Navigator's
  `null as unknown as Researcher` type-lie; Navigator calls it directly.
- getVisitedStates routes through successToolResult (gains the `action` field).
- First unit tests for tools.ts (validation paths + factories).

Deferred (documented): click/hover fallback-loop extraction (step 4) and the
disambiguateElements move (step 8) are behavior-risky without a live browser;
the currentActionResult alias is cosmetic. countAriaChanges unification is
handled by the plan-015 PR. All behavior-preserving; 63 integration + 770 unit
pass, tsc reduced by 1 in touched files.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Explorbot Self-Regression

Commit 2a697a5 · run

Scenario Result Attempts Duration
basic (native) PASS 1/3 6m
experience: control OK — failed as expected 1/1 1m
experience: seeded PASS 1/3 51s

Attempt details

  • basic (native) attempt 1 — PASS: login evidence: PASS (post-login plan=true, post-login research=true); research: PASS (files=5, wellFormed=true, keywords=6/3); scenarios: PASS (tests=7/5, features=4/3); tests passed: PASS (5 passed, 0 failed (reporter: 5 passed, 0 failed))
  • experience: control attempt 1 — PASS: control: OK — failed as expected (0 passed, 1 failed)
  • experience: seeded attempt 1 — PASS: seeded: PASS (1 passed, 0 failed)

Session analysis — basic (native):

Session Analysis

The issue tracking feature was tested for core operations: creation, filtering by label, keyword search, status filtering, and detail view. The keyword search and status filtering work correctly. The label filter test has a verification gap—it confirms the URL changes but does not verify the actual filtered results.

Coverage

  • Pages: /issues, /issues/{id}
  • Features: Issue creation, label filtering, keyword search, status filtering, issue detail view

What works

  • Issue creationET-1 Create a new issue with title and verify it appears in the list
  • Keyword searchET-3 Search for an issue by keyword and verify filtered results
  • Status filteringET-4 Filter issues by status and verify only matching issues show
  • Issue detail viewET-5 Open an existing issue to view its details

Execution Issues

  • ET-2 Filter issues by 'bug' label and verify only bug issues are shown — passed vacuously, only verified URL contains ?label=1, did not verify the filtered list actually shows only bug-labeled issues

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.

2 participants