@@ -44,34 +44,21 @@ and chunking text.
4444
4545## Source Map
4646
47- All code lives in a single ` main ` package across three files :
47+ All code lives in a single ` main ` package, organized by concern :
4848
4949| File | Lines | Responsibility |
5050| ----------------------| -------| ----------------|
51- | ` main.go ` | ~ 2100 | Everything: CLI, config management, API clients, chunking, splitting |
51+ | ` main.go ` | ~ 450 | CLI entry point (` main ` , ` run ` , ` normalizeArgs ` ), flag parsing, ` runOptions ` |
52+ | ` types.go ` | ~ 85 | All struct types (OpenAI/Gemini API request/response, ` Config ` , ` PostAction ` ) |
53+ | ` config.go ` | ~ 345 | Config loading, validation, creation, API key storage |
54+ | ` openai.go ` | ~ 530 | OpenAI API client, transcription, chunked processing, merge logic |
55+ | ` gemini.go ` | ~ 415 | Gemini API client, transcription, chunked processing, merge logic |
56+ | ` provider.go ` | ~ 140 | Provider dispatch with automatic fallback |
57+ | ` util.go ` | ~ 190 | Utilities (string ops, file ops, audio splitting, model context limits), constants, shared state |
5258| ` default_config.go ` | ~ 430 | Default YAML config template with 18 built-in post-actions |
53- | ` main_test.go ` | ~ 1130 | Unit tests (config validation, helpers, provider logic) |
59+ | ` main_test.go ` | ~ 3340 | Table-driven unit tests with httptest-based API mocking |
5460
55- There are no internal packages. Functions are organized by concern within ` main.go ` :
56-
57- ```
58- main.go layout (by line range):
59- 23-100 Type definitions (API request/response structs, Config, PostAction)
60- 102-122 multiStringFlag (custom flag type for -transcript)
61- 126-157 Constants and getModelContextLimit()
62- 159-577 main() + CLI flow
63- 579-696 Config: findAction, loadConfigActions, validateConfig, createDefaultConfig
64- 697-919 Config persistence: resetConfig, storeAPIKey, storeGeminiAPIKey, setDefaultProvider
65- 921-934 parseRateLimitWaitTime
66- 937-1104 API clients: makeOpenAIRequest, makeGeminiRequest (with retry)
67- 1106-1122 getMimeType
68- 1124-1373 Gemini pipeline: transcribe, split, process, chunk, merge
69- 1375-1509 Provider dispatchers with fallback
70- 1511-1568 Auto-select actions (Gemini)
71- 1570-1770 OpenAI pipeline: process, chunk, merge, hierarchical merge
72- 1772-1868 Auto-select actions (OpenAI), truncateString, splitIntoSentences
73- 1870-2099 OpenAI transcription: transcribeAudio, getFileSize, splitAudioFile, shellescape
74- ```
61+ There are no internal packages. Each file groups related functions:
7562
7663## Key Design Decisions
7764
@@ -146,9 +133,11 @@ This means:
146133
147134### Global Mutable State
148135
149- ` postActions ` is a package-level ` []PostAction ` that ` loadConfigActions() ` writes
150- to and ` findAction() ` reads from. This is the only piece of global mutable state.
151- Tests must set it explicitly before assertions.
136+ ` postActions ` is a package-level ` []PostAction ` (declared in ` util.go ` ) that
137+ ` loadConfigActions() ` writes to and ` findAction() ` reads from. ` openAIBaseURL `
138+ and ` geminiBaseURL ` are package-level vars (also in ` util.go ` ) that default to
139+ production endpoints but can be overridden in tests to point at ` httptest.Server `
140+ instances. Tests must set these explicitly before assertions.
152141
153142## Invariants
154143
@@ -189,13 +178,19 @@ orphaned temp dirs may remain in the OS temp directory.
189178
190179## Testing
191180
192- Tests live in ` main_test.go ` and cover config validation, helper functions, and
193- provider-specific logic. All tests are unit-level — no integration tests hit
194- real APIs.
181+ Tests live in ` main_test.go ` (~ 3340 lines, ~ 73% coverage) and cover:
182+ - Pure function tests (string utils, flag parsing, model context limits)
183+ - HTTP-mocked API tests via ` httptest.Server ` (OpenAI and Gemini request/response)
184+ - Provider dispatch tests (success paths, fallback in both directions, both-fail)
185+ - Chunked processing and merge logic
186+ - Integration tests for ` run() ` (list actions, transcript mode, error paths)
187+
188+ No tests hit real APIs.
195189
196190Key patterns:
197191- Table-driven sub-tests with ` t.Run `
198192- ` t.TempDir() ` for filesystem isolation
193+ - ` overrideBaseURLs(t, openAI, gemini) ` helper to redirect API calls to test servers
199194- ` os.Setenv("HOME", tmpDir) ` to isolate config operations (restored via ` defer ` )
200195- The global ` postActions ` slice is set directly in tests that need it
201196
0 commit comments