Skip to content

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

Merged
DenysKuchma merged 2 commits into
mainfrom
refactor/tools-boilerplate-consolidation
Jul 16, 2026
Merged

refactor: extract shared tool boilerplate in tools.ts (plan 018)#89
DenysKuchma merged 2 commits 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

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Explorbot Self-Regression

Commit 8c26b11 · run

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

Attempt details

  • basic (native) attempt 1 — FAIL: login evidence: PASS (post-login plan=true, post-login research=true); research: PASS (files=6, wellFormed=true, keywords=7/3); scenarios: PASS (tests=7/5, features=4/3); tests passed: FAIL (4 passed, 1 failed (reporter: 4 passed, 1 failed))
  • basic (native) attempt 2 — PASS: login evidence: PASS (post-login plan=true, post-login research=true); research: PASS (files=6, wellFormed=true, keywords=7/3); scenarios: PASS (tests=6/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 works end-to-end: creating, filtering by label/status, searching, and viewing details all function correctly. The core flows hold, but test automation experienced repeated locator/click failures that required retries before passing.

Coverage

  • Pages: /issues, /issues?new=1, /issues/6
  • Features: Create issue, filter by label, filter by status, search, view details

What works

  • Issue creationET-1 Create a new issue and verify it appears in the issues list
  • Label filteringET-2 Filter issues by label and verify results
  • Status filteringET-3 Filter issues by status and verify results
  • SearchET-4 Search for an existing issue and verify results
  • Viewing issue detailsET-5 View issue details by clicking on an issue title

Execution Issues

  • ET-1 Create a new issue — required 2 retry attempts with different form selectors, form fill failed twice before succeeding
  • ET-5 View issue details — click failed 5 times with various selectors before navigating to detail page, then passed

Defects

(None identified — all failures were automation-related, not product failures.)

@DenysKuchma
DenysKuchma merged commit 714fa13 into main Jul 16, 2026
3 checks passed
@DenysKuchma
DenysKuchma deleted the refactor/tools-boilerplate-consolidation branch July 16, 2026 14:03
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