# 01-testability-refactoring — FINAL Report

## Run metadata

- **Mode**: guided (invoked by autodev existing-code Step 4)
- **Input source**: `autodev-testability-analysis` → `list-of-changes.md`
- **Epic**: [AZ-447](https://denyspopov.atlassian.net/browse/AZ-447)
- **Tasks**: AZ-448 .. AZ-454 (7 tasks; all `In Testing` in Jira)
- **Run folder**: `_docs/04_refactoring/01-testability-refactoring/`

## Phases executed

| Phase | Status | Notes |
|-------|--------|-------|
| 0 — Baseline | n/a (testability run; no test suite to baseline) | Skipped by design |
| 1 — Discovery | done | `list-of-changes.md` (7 entries) + `deferred_to_refactor.md` (13 entries) |
| 2 — Analysis | done | `analysis/research_findings.md`, `analysis/refactoring_roadmap.md`, 7 task specs written, epic + tasks created in Jira |
| 3 — Safety Net | **skipped by design** | Testability runs have no pre-existing tests — compensating control was the user-approved Phase-1 `list-of-changes.md` gate |
| 4 — Execution | done | 2 batches (Batch 1: AZ-450/451/452/454; Batch 2: AZ-448/449/453); commits `<batch-1-sha>` and `ed81034` |
| 4.5 — Testability Changes Summary | done; acknowledged | `testability_changes_summary.md`; user acked via autodev Step 4 gate |
| 5 — Test Sync | no-op | No tests exist yet; autodev hands off to Step 5 (Decompose Tests) for the initial test suite |
| 6 — Verification | done (static-only) | tsc clean, grep checks green (see `testability_changes_summary.md` § Verification snapshot) |
| 7 — Documentation | partial / deferred | `.env.example` documents the new env vars and `src/vite-env.d.ts` declares them. Module-doc updates (e.g. `_docs/02_document/modules/src__api__client.md`) are deferred to autodev Step 13 (Update Docs) on the first Phase B cycle to keep this testability run minimal-surgical. |

## Baseline vs final metrics

A behavioral baseline could not be captured (no test suite). The verification axis for this run is the static-check matrix on the testability surface:

| Check | Before | After |
|-------|--------|-------|
| Hardcoded OWM API key in `src/` | 1 literal in `flightPlanUtils.ts:60` | 0 |
| Hardcoded `unpkg.com` URL in `src/` | 1 in `mapIcons.ts:18` | 0 |
| Direct `window.location.href` writes in `src/api/client.ts` | 1 inline write | 1 (only inside default `navigateToLoginImpl`) |
| Vite env vars declared | 0 | 5 (`VITE_API_BASE_URL`, `VITE_OWM_API_KEY`, `VITE_OWM_BASE_URL`, `VITE_OSM_TILE_URL`, `VITE_ESRI_TILE_URL`) |
| `.env.example` documentation | absent | present |
| `bun run tsc --noEmit` | clean | clean |

## Changes summary

See `testability_changes_summary.md`. 7 changes applied across 4 files:

- `src/features/flights/flightPlanUtils.ts` — C01 + C02 (OWM config extraction)
- `src/features/flights/types.ts` — C03 (tile URL extraction)
- `src/features/flights/mapIcons.ts` — C04 (bundled marker icon)
- `src/api/client.ts` — C05 + C06 + C07 (`getApiBase`, `setNavigateToLogin`, JSDoc on `setToken/getToken`)
- `src/api/sse.ts` — C05 (consumes `getApiBase`)
- `src/vite-env.d.ts`, `.env.example` — new env var declarations / templates

## Remaining items

- All 13 deferred items live in `deferred_to_refactor.md` (D01–D13) — candidates for autodev Step 8 (Refactor) or Phase B feature cycles, not this run.
- Module-doc updates listed under Phase 7 above (deferred to autodev Step 13).

## Lessons learned

- Scope discipline held: every rejected item that drifted into product / UX / parent-suite territory was caught at Phase 1 review and moved to `deferred_to_refactor.md` instead of silently expanding the run.
- The accidental staging of `tsconfig.tsbuildinfo` (caught + fixed mid-Batch-1) was a reminder to keep build-cache files out of git — `.gitignore` was updated in the same batch.
- Splitting C01/C02 (same file, conceptually one change) into two Jira tickets kept the audit trail per-restriction (O6 vs E2E-determinism) clean but cost a tiny extra commit; acceptable trade-off for tracker hygiene.
