test: cover the day cache and cli dispatch directly - #48
Merged
Conversation
cache.js had no test importing it, and cli.js was tested only through its auth commands. Both now have a file of their own. tests/cache.test.js proves the policy the module's comment states: a miss fetches, parses, and writes under host and extension; a fresh copy is served from disk without touching the network; a copy older than a day is refetched and replaced; a body the parser rejects is never written, and a stale good copy survives such a refetch; a cache directory that cannot be created costs only the refetch. The network is a local proxy that records what it sees, so "never asked" is asserted, not assumed. tests/cli.test.js spawns the real binary against a throwaway OC_HOME with a page seeded straight into a session file, so read, next, find, and do on text all have something to answer with and nothing fetches. It covers help on no command and both help flags, the help text naming every dispatchable command once, unknown first words, a site name reaching the shortcut resolver before being called unknown, budget and session name validation running before any command, the nothing-open message from every session command, the usage lines of open, raw, read, find, and do, do on a text number reading in place with a recording proxy proving no request left, the four planned commands failing with one line that names themselves, sites, and flags placed before or after the command. Each test was checked against a deliberate break in the code it guards.
only-cli
force-pushed
the
test/cache-and-cli-dispatch
branch
from
September 2, 2026 14:38
0a43456 to
5657d60
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First step on test coverage: the two modules with the thinnest direct coverage.
src/cache.jshad no test importing it, andsrc/cli.jswas exercised only through its auth commands intests/cli-auth.test.js.tests/cache.test.js (7 tests)
The network is a local HTTP proxy that records every request, reached through
HTTP_PROXYthe same way the fetch tests do, so "the network was never asked" is asserted rather than assumed. Nothing leaves the machine.<kind>/<host><ext>.tests/cli.test.js (18 tests)
Each case spawns the real binary against a throwaway
OC_HOME. The page under test is seeded straight into a session file, soread,next,find, anddoon text all have something to answer with, and no test fetches.--help, and-hprint the usage and exit 0.--help.--budgetmust be a positive number and--sessionmust be a safe filename, both checked before any command runs.read,next,find, anddowith nothing open all say to runopenfirst.openandrawwith no URL print a usage line.read <n>prints the region, and a bad number gives usage rather than a stack trace.nextreports the end of a page that fit in one render.findjoins the rest of argv into one query, and fails with usage on none.doon a text number reads it in place; a recording proxy proves no request left.dowith no number, or a number the page lacks, fails in one line.fill,submit,back, andsessionfail with the same one-line message naming themselves.siteslists the bundled shortcuts.Verification
Every test was checked against a deliberate break in the code it guards, each caught by the test meant to catch it:
--budgetcheck removedfillwired tosubmitfindjoins argv with''Full suite: 212 passing (was 188), offline, no new dependencies.