mirror of
https://gh-proxy.org/https://github.com/klinsmaya/multica.git
synced 2026-11-09 09:56:47 +08:00
* fix(test): isolate test home on Windows across config-writing packages
Tests that only redirect HOME still resolve ~/.multica against the real
home on Windows: os.UserHomeDir reads USERPROFILE, not HOME. SaveCLIConfig
then writes test fixtures over a real default-profile config.json.
Reproduced on a Windows host by running `go test ./internal/cli ./cmd/multica`
on an unmodified tree: the real ~/.multica/config.json was replaced with the
test fixture {"token": "mul_owner_pat"}, dropping server_url, app_url and
workspace_id. The running daemon keeps its in-memory config, so the damage
only surfaces on the next restart as an auth failure.
Redirect both home variables process-wide in TestMain for the packages that
resolve ~/.multica (cmd/multica, internal/cli, internal/daemon), and route
per-test home redirects through a redirectTestHome helper that sets HOME and
USERPROFILE together. Per-test t.Setenv overrides still win.
Comparison on the same host, same packages:
without this change: 6 internal/cli + 10 cmd/multica failures, real config overwritten
with this change: 1 + 5 failures (all pre-existing Windows cases), config intact
Co-authored-by: multica-agent <[email protected]>
* fix(test): fail closed when isolating test homes
Co-authored-by: multica-agent <[email protected]>
* test(ghsnapshot): isolate cursor fixture from other packages
Co-authored-by: multica-agent <[email protected]>
---------
Co-authored-by: ZhangRui <[email protected]>
Co-authored-by: multica-agent <[email protected]>
Co-authored-by: Yushen <[email protected]>
26 lines
1.3 KiB
Go
26 lines
1.3 KiB
Go
// Package testutil holds shared server test infrastructure: DB fixture
|
|
// builders, HTTP assertions, and process-environment isolation helpers.
|
|
//
|
|
// It exists because the cost of changing shared behaviour was scaling with
|
|
// the number of test files. Before this package `internal/handler` alone held
|
|
// ~1000 hand-written `INSERT INTO ... RETURNING id` blocks, ~1150
|
|
// `DELETE FROM` cleanups and ~1200 copies of the
|
|
// recorder/call/status/decode quartet, each one an independent statement of
|
|
// the same contract. Changing an insert's column set, or the shape of a
|
|
// failure message, meant editing every copy.
|
|
//
|
|
// Two rules keep it that way:
|
|
//
|
|
// - New DB-backed tests build their rows through a Fixture and drive
|
|
// handlers through Call. Do not open-code an INSERT + t.Cleanup pair or a
|
|
// recorder/status/decode quartet in a new test.
|
|
// - Helpers here stay behaviour-free. They insert rows, run handlers and
|
|
// report mismatches; they never assert a product rule on the test's
|
|
// behalf. A helper that knows what a correct response looks like moves
|
|
// the assertion out of the test that is supposed to make it.
|
|
//
|
|
// The package imports "testing" and must only be imported from _test files.
|
|
// Importing it from production code links the testing flag set into the
|
|
// binary.
|
|
package testutil
|