cfgit 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cfgit-0.3.0 → cfgit-0.4.0}/PKG-INFO +10 -1
- {cfgit-0.3.0 → cfgit-0.4.0}/README.md +9 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/USAGE.md +16 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/pyproject.toml +2 -2
- {cfgit-0.3.0 → cfgit-0.4.0}/pyproject.toml +1 -1
- {cfgit-0.3.0 → cfgit-0.4.0}/skills/cfgit/SKILL.md +8 -3
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/cli/main.py +33 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/mcp/server.py +16 -0
- cfgit-0.4.0/src/cfg/update.py +263 -0
- cfgit-0.4.0/tests/test_update_check.py +189 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/.github/workflows/ci.yml +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/.github/workflows/publish.yml +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/.gitignore +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/CONTRIBUTING.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/CREDITS.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/LICENSE +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/NOTICE +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/SECURITY.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/ADAPTERS.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/AGENTS.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/BRANCHING_PLAN.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/CONFIGURATION.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/IDENTITY_AND_ATTRIBUTION.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/PUBLISHING.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/README.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/SPEC.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/SPEC_CORE.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/screenshots/01-diff.png +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/screenshots/02-impact.png +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/docs/screenshots/03-scoped-impact.png +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/examples/.cfg.toml +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/examples/cfgit-support-demo.toml +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/examples/seed_support_demo.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/README.md +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/overview.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/providers/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/providers/base.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/providers/claude.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/providers/factory.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/providers/gemini.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/plugins/cfg_impact/cfg_impact/providers/openai_provider.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/adapters/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/adapters/base.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/adapters/mongo.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/adapters/postgres.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/approval/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/approval/base.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/cli/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/authz.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/config.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/diff.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/engine.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/hashing.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/identity.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/core/remedy.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/interfaces/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/interfaces/actions.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/mcp/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/ui/__init__.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/src/cfg/ui/server.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_adapter_contract_live.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_authz.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_awareness.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_commit_dry_run.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_config.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_config_discovery.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_console_script.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_core_purity.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_engine_safety.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_export_import.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_hashing.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_identity.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_impact_boundary.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_mcp_identity.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_mongo_history.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_output_mode.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_postgres_history.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_remedy.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_set_fields.py +0 -0
- {cfgit-0.3.0 → cfgit-0.4.0}/tests/test_ui_server.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cfgit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Git-style history, diff, drift detection, and rollback for live database records without migrating or owning your datastore
|
|
5
5
|
Project-URL: Homepage, https://github.com/AusafMo/cfgit
|
|
6
6
|
Project-URL: Repository, https://github.com/AusafMo/cfgit
|
|
@@ -614,9 +614,16 @@ cfg restore --as-of <date> --dry-run -m "message"
|
|
|
614
614
|
cfg restore --tag <name> --dry-run -m "message"
|
|
615
615
|
cfg fsck
|
|
616
616
|
cfg whoami
|
|
617
|
+
cfg check-update [--snooze [DAYS]]
|
|
617
618
|
cfg ui
|
|
618
619
|
```
|
|
619
620
|
|
|
621
|
+
cfgit checks PyPI for a newer release on cheap read commands (throttled to once a day) and, for an
|
|
622
|
+
interactive terminal, prints a one-line nudge to stderr with what's new — it never upgrades for
|
|
623
|
+
you (run `pip install -U cfgit`) and never prints on `--json`/piped output. `cfg check-update`
|
|
624
|
+
forces a check; `cfg check-update --snooze 30` silences it for 30 days; `CFGIT_NO_UPDATE_CHECK=1`
|
|
625
|
+
disables it entirely.
|
|
626
|
+
|
|
620
627
|
Every command supports `--json` for scripts and agents. By default output is human-readable
|
|
621
628
|
when stdout is a terminal and JSON when piped or redirected; set `CFG_OUTPUT=json|human|auto`
|
|
622
629
|
to control this, and `--json` always forces JSON.
|
|
@@ -724,6 +731,7 @@ Tools include:
|
|
|
724
731
|
- `cfg_bulk_commit`
|
|
725
732
|
- `cfg_set`
|
|
726
733
|
- `cfg_export`
|
|
734
|
+
- `cfg_import`
|
|
727
735
|
- `cfg_branch_list`
|
|
728
736
|
- `cfg_branch_create`
|
|
729
737
|
- `cfg_branch_delete`
|
|
@@ -744,6 +752,7 @@ Tools include:
|
|
|
744
752
|
- `cfg_whoami`
|
|
745
753
|
- `cfg_init`
|
|
746
754
|
- `cfg_identity_hash`
|
|
755
|
+
- `cfg_check_update`
|
|
747
756
|
|
|
748
757
|
A portable skill lives at `skills/cfgit/SKILL.md`.
|
|
749
758
|
`cfg_impact` accepts the same `against` list/string as the CLI `--against` flag,
|
|
@@ -381,9 +381,16 @@ cfg restore --as-of <date> --dry-run -m "message"
|
|
|
381
381
|
cfg restore --tag <name> --dry-run -m "message"
|
|
382
382
|
cfg fsck
|
|
383
383
|
cfg whoami
|
|
384
|
+
cfg check-update [--snooze [DAYS]]
|
|
384
385
|
cfg ui
|
|
385
386
|
```
|
|
386
387
|
|
|
388
|
+
cfgit checks PyPI for a newer release on cheap read commands (throttled to once a day) and, for an
|
|
389
|
+
interactive terminal, prints a one-line nudge to stderr with what's new — it never upgrades for
|
|
390
|
+
you (run `pip install -U cfgit`) and never prints on `--json`/piped output. `cfg check-update`
|
|
391
|
+
forces a check; `cfg check-update --snooze 30` silences it for 30 days; `CFGIT_NO_UPDATE_CHECK=1`
|
|
392
|
+
disables it entirely.
|
|
393
|
+
|
|
387
394
|
Every command supports `--json` for scripts and agents. By default output is human-readable
|
|
388
395
|
when stdout is a terminal and JSON when piped or redirected; set `CFG_OUTPUT=json|human|auto`
|
|
389
396
|
to control this, and `--json` always forces JSON.
|
|
@@ -491,6 +498,7 @@ Tools include:
|
|
|
491
498
|
- `cfg_bulk_commit`
|
|
492
499
|
- `cfg_set`
|
|
493
500
|
- `cfg_export`
|
|
501
|
+
- `cfg_import`
|
|
494
502
|
- `cfg_branch_list`
|
|
495
503
|
- `cfg_branch_create`
|
|
496
504
|
- `cfg_branch_delete`
|
|
@@ -511,6 +519,7 @@ Tools include:
|
|
|
511
519
|
- `cfg_whoami`
|
|
512
520
|
- `cfg_init`
|
|
513
521
|
- `cfg_identity_hash`
|
|
522
|
+
- `cfg_check_update`
|
|
514
523
|
|
|
515
524
|
A portable skill lives at `skills/cfgit/SKILL.md`.
|
|
516
525
|
`cfg_impact` accepts the same `against` list/string as the CLI `--against` flag,
|
|
@@ -377,3 +377,19 @@ export CFG_AUTHOR=you@example.com # default author (open identity mo
|
|
|
377
377
|
cfgit also discovers `.cfg.toml` by walking up from the current directory, so you can run it
|
|
378
378
|
from a subdirectory without `--config-file`. Global flags (`--config-file`, `--env`, `--author`,
|
|
379
379
|
`--branch`, `--json`) go before the subcommand: `cfg --env prod status`.
|
|
380
|
+
|
|
381
|
+
## Updates
|
|
382
|
+
|
|
383
|
+
cfgit checks PyPI for a newer release on cheap read commands (`status`/`doctor`/`whoami`/`log`),
|
|
384
|
+
throttled to once a day. For an interactive terminal it prints a one-line nudge to stderr with a
|
|
385
|
+
short "what's new" excerpt from the release notes — never on `--json`/piped output, and it never
|
|
386
|
+
upgrades for you:
|
|
387
|
+
|
|
388
|
+
```bash
|
|
389
|
+
cfg check-update # force a check now (shows what's new + the release link)
|
|
390
|
+
cfg check-update --snooze 30 # don't remind me for 30 days
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Set `CFGIT_NO_UPDATE_CHECK=1` to disable the check entirely. Over MCP, the `cfg_check_update` tool
|
|
394
|
+
does the same (pass `snooze_days` to snooze); agents should offer the upgrade but never run it.
|
|
395
|
+
The check is best-effort — if the network is unavailable it stays silent.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "cfgit-impact"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "Optional cfgit plugin for deterministic system-impact summaries and opt-in LLM narration of database record diffs"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
license = "Apache-2.0"
|
|
8
8
|
authors = [{ name = "Mohammad Ausaf" }]
|
|
9
9
|
dependencies = [
|
|
10
|
-
"cfgit>=0.
|
|
10
|
+
"cfgit>=0.4.0,<0.5.0",
|
|
11
11
|
"httpx>=0.27",
|
|
12
12
|
]
|
|
13
13
|
|
|
@@ -13,7 +13,9 @@ Use cfgit as the safety layer around a live datastore. The app still reads and w
|
|
|
13
13
|
- Never use cross-project Mongo URIs for writes. Remote managed Mongo writes are forbidden unless the user explicitly grants a per-turn exception and asks for that exact target.
|
|
14
14
|
- Treat `changed_outside_cfgit` as the central state. Do not commit over it. Run `cfg diff`, explain what changed, then `cfg adopt` if the user wants to fold that live state into history.
|
|
15
15
|
- If `[branches] enabled = true`, draft risky changes on a non-main branch and open a cfgit PR. Branch commits and PR creation do not mutate runtime; `cfg pr merge` is the only branch command that does.
|
|
16
|
-
-
|
|
16
|
+
- At the start of a cfgit session, call `cfg_check_update` (or `cfg check-update --json`). If `data.update_available` is true and `data.snoozed` is false, tell the user the new version, show `data.notes` (what's new), and offer to upgrade (`pip install -U cfgit`) or snooze — call `cfg_check_update` with `snooze_days=30` if they want to be reminded later. NEVER upgrade for them. It is best-effort and silent when there is nothing to say; skip if `data.disabled` (they set `CFGIT_NO_UPDATE_CHECK`).
|
|
17
|
+
- Prefer `--json` for agent parsing. Output is otherwise human-on-a-TTY / JSON-when-piped; `CFG_OUTPUT=json|human|auto` overrides. To avoid repeating flags, `CFG_ENV`, `CFG_CONFIG`, and `CFG_AUTHOR` set session defaults, and cfgit discovers `.cfg.toml` by walking up from the cwd.
|
|
18
|
+
- Run `cfg doctor --status` to confirm where you are pointed (config, env, target db, identity mode + whether verified, reachability, tracked/drift counts) before mutating an unfamiliar env. It warns if a `needs_approval` env is still in `open` identity mode — writes there succeed UNAUDITED; surface that to the user.
|
|
17
19
|
- Use deterministic `cfg impact` first. Add `--llm` only when the user asks for LLM narration and the impact plugin is installed. Use `--against <collection:id>` when the user wants narration scoped to specific related records instead of the whole system.
|
|
18
20
|
- Before the FIRST `cfg import` against a new database or `.cfg.toml`, run `cfg doctor` (read-only). It reports every secret-deny match, oversized field, and key issue at once, with paste-ready `secret_fields`/`ignore_fields` snippets. Fix `.cfg.toml` from its output, then import. This avoids import failing one secret at a time.
|
|
19
21
|
- In `authenticated` or `enforced` identity mode, the process must already have a verified identity source, usually `CFGIT_IDENTITY_TOKEN` or a per-user DB principal. `--author` and MCP `author` are hints only; cfgit rejects them if they do not match the verified identity.
|
|
@@ -53,7 +55,7 @@ Use cfgit as the safety layer around a live datastore. The app still reads and w
|
|
|
53
55
|
- Every outcome now carries a top-level `next` block (why + remedy + copy-paste `commands`);
|
|
54
56
|
on a refusal, follow `next.commands` rather than guessing.
|
|
55
57
|
- For a coupled multi-record change, write a batch JSON file and run `cfg commit --bulk-from <file> -m "<message>" --json`. The batch file can be `[{"record":"collection:id","doc":{...}}]` or `{"collection:id": {...}}`. Preview a collection-scale batch first with `cfg commit --bulk-from <file> --dry-run --json` — it reports each record's `would_commit`/`noop`/`changed_outside_cfgit` and writes nothing.
|
|
56
|
-
- Before a risky bulk change, snapshot the current live docs with `cfg export --out backup.json --json` (a portable, re-importable artifact stamped with head seq/oid). To roll back, `cfg import --from backup.json -m "<message>" --json` writes them back through the drift-guarded path (preview with `--dry-run`). For an in-tool rollback with no file, use `cfg tag` + `cfg restore --tag` instead.
|
|
58
|
+
- Before a risky bulk change, snapshot the current live docs with `cfg export --out backup.json --json` (a portable, re-importable artifact stamped with head seq/oid). If export prints a size warning, the config may be pointed at a data-plane collection (events/content/jobs) cfgit is not built to version — flag it. To roll back, `cfg import --from backup.json -m "<message>" --json` writes them back through the drift-guarded path (preview with `--dry-run`). If it returns `partial` with `cancelled: true` (the user interrupted), already-applied records are durable and rerunning the same command resumes. For an in-tool rollback with no file, use `cfg tag` + `cfg restore --tag` instead.
|
|
57
59
|
- For a draft branch, use `cfg --branch <branch> commit <record> --from <file> -m "<message>" --json` or `cfg --branch <branch> commit --bulk-from <file> -m "<message>" --json`. This writes cfgit refs only; runtime is unchanged.
|
|
58
60
|
- If commit returns `changed_outside_cfgit`, stop and inspect drift.
|
|
59
61
|
- If bulk commit returns `blocked`, no record was applied; inspect `failed`. If it returns `partial`, some records were applied before a race/failure; inspect `results`, `failed`, and `pending` before continuing.
|
|
@@ -87,7 +89,9 @@ If the cfgit MCP server is available, prefer its tools over shelling out:
|
|
|
87
89
|
- `cfg_impact`
|
|
88
90
|
- `cfg_commit`
|
|
89
91
|
- `cfg_bulk_commit`
|
|
92
|
+
- `cfg_set` for a few scalar field edits (routes through the drift-guarded commit path)
|
|
90
93
|
- `cfg_export`
|
|
94
|
+
- `cfg_import` (pass `from_export` to restore a snapshot; `dry_run` to preview)
|
|
91
95
|
- `cfg_branch_list`
|
|
92
96
|
- `cfg_branch_create`
|
|
93
97
|
- `cfg_branch_delete`
|
|
@@ -108,7 +112,8 @@ If the cfgit MCP server is available, prefer its tools over shelling out:
|
|
|
108
112
|
- `cfg_whoami`
|
|
109
113
|
- `cfg_init`
|
|
110
114
|
- `cfg_identity_hash` for setup only. Prefer the local CLI for real tokens because MCP clients may log tool inputs.
|
|
115
|
+
- `cfg_check_update` — check PyPI for a newer cfgit; pass `snooze_days` to snooze. Never upgrades.
|
|
111
116
|
|
|
112
|
-
Every MCP tool returns the same envelope
|
|
117
|
+
Every MCP tool returns the same envelope: `status`, `code`, `message`, `data`, plus top-level `state` and `next`. `state` echoes the outcome's terminal state (e.g. `changed_outside_cfgit`, `noop`, `blocked`, `would_commit`); `next` is a self-teaching remedy `{why, remedy, commands}` when the outcome needs one, else null. Branch on `state` and follow `next.commands` on a refusal instead of guessing.
|
|
113
118
|
For MCP bulk commits, pass `items` as structured JSON (`[{record, doc}]`) when the client supports it; use a JSON string only when the client cannot send nested objects cleanly.
|
|
114
119
|
For MCP history/env mismatches, branch on `status="error"` and `code=6`; surface the `message` to the user and do not continue mutation.
|
|
@@ -68,12 +68,21 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
68
68
|
except ValueError as exc:
|
|
69
69
|
_emit_error("error", str(exc), args)
|
|
70
70
|
return EXIT_ARG
|
|
71
|
+
if args.cmd == "check-update":
|
|
72
|
+
from cfg import update
|
|
73
|
+
|
|
74
|
+
if args.snooze is not None:
|
|
75
|
+
_emit(update.snooze(args.snooze), json_mode=args.json)
|
|
76
|
+
return EXIT_OK
|
|
77
|
+
_emit(update.check(force=True).to_json(), json_mode=args.json)
|
|
78
|
+
return EXIT_OK
|
|
71
79
|
try:
|
|
72
80
|
project = load_config(args.config_file)
|
|
73
81
|
engine = _engine(project, args.env, author=args.author)
|
|
74
82
|
_warn_open_mode(engine, args)
|
|
75
83
|
result, code = _dispatch(engine, args)
|
|
76
84
|
_emit(result, json_mode=args.json, record=getattr(args, "record", None))
|
|
85
|
+
_maybe_update_nudge(args)
|
|
77
86
|
return code
|
|
78
87
|
except AmbiguousConfig as exc:
|
|
79
88
|
_emit_error("bad_config", str(exc), args, exc=exc)
|
|
@@ -245,6 +254,10 @@ def _parser() -> argparse.ArgumentParser:
|
|
|
245
254
|
p_identity_hash.add_argument("token", nargs="?")
|
|
246
255
|
p_identity_hash.add_argument("--stdin", action="store_true")
|
|
247
256
|
|
|
257
|
+
p_update = sub.add_parser("check-update", help="check PyPI for a newer cfgit (never upgrades for you)")
|
|
258
|
+
p_update.add_argument("--snooze", nargs="?", type=int, const=30, default=None,
|
|
259
|
+
metavar="DAYS", help="silence the update nudge for DAYS (default 30)")
|
|
260
|
+
|
|
248
261
|
p_ui = sub.add_parser("ui")
|
|
249
262
|
p_ui.add_argument("--host", default="127.0.0.1")
|
|
250
263
|
p_ui.add_argument("--port", type=int, default=8765)
|
|
@@ -640,6 +653,26 @@ def _load_json_any(path: str) -> Any:
|
|
|
640
653
|
|
|
641
654
|
_MUTATING_CMDS = {"commit", "set", "edit", "adopt", "import", "restore"}
|
|
642
655
|
|
|
656
|
+
# Cheap, read-only commands safe to piggyback a throttled update check onto — never a write path,
|
|
657
|
+
# so a version check never sits in front of a prod mutation.
|
|
658
|
+
_READ_COMMANDS = {"status", "doctor", "whoami", "log"}
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
def _maybe_update_nudge(args: argparse.Namespace) -> None:
|
|
662
|
+
"""Deterministic npm/brew-style nudge: after a cheap read command, if a newer cfgit is on
|
|
663
|
+
PyPI (throttled daily, snooze-aware, kill-switchable), print one line to stderr — but only
|
|
664
|
+
for an interactive human (TTY, not --json). Never touches stdout; never raises."""
|
|
665
|
+
if args.cmd not in _READ_COMMANDS or getattr(args, "json", False) or not sys.stdout.isatty():
|
|
666
|
+
return
|
|
667
|
+
try:
|
|
668
|
+
from cfg import update
|
|
669
|
+
|
|
670
|
+
status = update.check()
|
|
671
|
+
if status.message:
|
|
672
|
+
print(status.message, file=sys.stderr)
|
|
673
|
+
except Exception: # noqa: BLE001 - a nudge must never break the command
|
|
674
|
+
pass
|
|
675
|
+
|
|
643
676
|
|
|
644
677
|
def _warn_open_mode(engine: Engine, args: argparse.Namespace) -> None:
|
|
645
678
|
"""Loud stderr warning when a mutating command runs against a needs_approval env still in
|
|
@@ -502,6 +502,22 @@ def cfg_identity_hash(token: str) -> dict[str, Any]:
|
|
|
502
502
|
}
|
|
503
503
|
|
|
504
504
|
|
|
505
|
+
@mcp.tool()
|
|
506
|
+
def cfg_check_update(snooze_days: int | None = None) -> dict[str, Any]:
|
|
507
|
+
"""Check PyPI for a newer cfgit release. Call this at the start of a cfgit session; if
|
|
508
|
+
`data.update_available` is true and not `data.snoozed`, tell the user the new version and
|
|
509
|
+
offer to upgrade (`pip install -U cfgit`) or to snooze. NEVER upgrade for them.
|
|
510
|
+
|
|
511
|
+
Pass `snooze_days` (e.g. 30) to record a "don't ask again for N days" snooze when the user
|
|
512
|
+
asks to be reminded later. Best-effort and fail-silent; honors CFGIT_NO_UPDATE_CHECK.
|
|
513
|
+
"""
|
|
514
|
+
from cfg import update
|
|
515
|
+
|
|
516
|
+
if snooze_days is not None:
|
|
517
|
+
return {"status": "ok", "code": actions.EXIT_OK, "message": "", "data": update.snooze(snooze_days)}
|
|
518
|
+
return {"status": "ok", "code": actions.EXIT_OK, "message": "", "data": update.check(force=True).to_json()}
|
|
519
|
+
|
|
520
|
+
|
|
505
521
|
def _call(
|
|
506
522
|
name: str,
|
|
507
523
|
payload: dict[str, Any],
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# Copyright 2026 Mohammad Ausaf. Licensed under the Apache License, Version 2.0.
|
|
2
|
+
"""Update check: is a newer cfgit on PyPI?
|
|
3
|
+
|
|
4
|
+
One engine, two surfaces — a deterministic CLI stderr nudge (npm/gh/brew style) and an MCP tool
|
|
5
|
+
that lets Claude offer the upgrade interactively. Both share this logic, so a 30-day snooze taken
|
|
6
|
+
in either place quiets both.
|
|
7
|
+
|
|
8
|
+
Principles:
|
|
9
|
+
- Never upgrades anything. It detects and reports; the human runs `pip install -U cfgit`.
|
|
10
|
+
- Best-effort and fail-silent: any network/parse/permission error means "say nothing", never an
|
|
11
|
+
error to the caller.
|
|
12
|
+
- Throttled: hits PyPI at most once per `CHECK_INTERVAL` (default daily), cached in a state file.
|
|
13
|
+
- Snoozable: "don't ask for 30 days" persists to the state file and is honored by both surfaces.
|
|
14
|
+
- Kill switch: `CFGIT_NO_UPDATE_CHECK=1` disables it entirely (opt-out, like npm's config).
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
import json
|
|
20
|
+
import os
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
from typing import Any
|
|
23
|
+
import urllib.error
|
|
24
|
+
import urllib.request
|
|
25
|
+
|
|
26
|
+
PACKAGE = "cfgit"
|
|
27
|
+
PYPI_URL = f"https://pypi.org/pypi/{PACKAGE}/json"
|
|
28
|
+
GITHUB_REPO = "AusafMo/cfgit"
|
|
29
|
+
GITHUB_LATEST_RELEASE_URL = f"https://api.github.com/repos/{GITHUB_REPO}/releases/latest"
|
|
30
|
+
RELEASES_PAGE = f"https://github.com/{GITHUB_REPO}/releases"
|
|
31
|
+
_NOTES_MAX_LINES = 5
|
|
32
|
+
STATE_DIR = Path.home() / ".cfgit"
|
|
33
|
+
STATE_FILE = STATE_DIR / "update-check.json"
|
|
34
|
+
CHECK_INTERVAL_S = 24 * 60 * 60 # network check at most once/day
|
|
35
|
+
DEFAULT_SNOOZE_DAYS = 30
|
|
36
|
+
_TIMEOUT_S = 2.0
|
|
37
|
+
_DISABLE_ENV = "CFGIT_NO_UPDATE_CHECK"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class UpdateStatus:
|
|
42
|
+
installed: str | None
|
|
43
|
+
latest: str | None
|
|
44
|
+
update_available: bool
|
|
45
|
+
checked: bool # did we actually reach PyPI this call?
|
|
46
|
+
snoozed: bool
|
|
47
|
+
disabled: bool
|
|
48
|
+
message: str | None # a ready-to-show nudge line, or None when there's nothing to say
|
|
49
|
+
notes: str | None = None # short "what's new" excerpt from the GitHub release, if fetched
|
|
50
|
+
notes_url: str | None = None # link to the full release notes
|
|
51
|
+
|
|
52
|
+
def to_json(self) -> dict[str, Any]:
|
|
53
|
+
return {
|
|
54
|
+
"installed": self.installed,
|
|
55
|
+
"latest": self.latest,
|
|
56
|
+
"update_available": self.update_available,
|
|
57
|
+
"checked": self.checked,
|
|
58
|
+
"snoozed": self.snoozed,
|
|
59
|
+
"disabled": self.disabled,
|
|
60
|
+
"message": self.message,
|
|
61
|
+
"notes": self.notes,
|
|
62
|
+
"notes_url": self.notes_url,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def installed_version() -> str | None:
|
|
67
|
+
"""Resolve the installed cfgit version, robust to editable/dev installs."""
|
|
68
|
+
try:
|
|
69
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
70
|
+
|
|
71
|
+
try:
|
|
72
|
+
return version(PACKAGE)
|
|
73
|
+
except PackageNotFoundError:
|
|
74
|
+
pass
|
|
75
|
+
except Exception: # noqa: BLE001
|
|
76
|
+
pass
|
|
77
|
+
# dev fallback: read version straight from pyproject.toml at the repo root
|
|
78
|
+
try:
|
|
79
|
+
import tomllib # py311+
|
|
80
|
+
|
|
81
|
+
root = Path(__file__).resolve().parents[2]
|
|
82
|
+
data = tomllib.loads((root / "pyproject.toml").read_text(encoding="utf-8"))
|
|
83
|
+
return str(data["project"]["version"])
|
|
84
|
+
except Exception: # noqa: BLE001
|
|
85
|
+
return None
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def check(*, force: bool = False, now: float | None = None) -> UpdateStatus:
|
|
89
|
+
"""Return the current update status, honoring the kill switch, throttle, and snooze.
|
|
90
|
+
|
|
91
|
+
`force=True` bypasses the throttle (but not the kill switch) — used by an explicit
|
|
92
|
+
`cfg check-update`. `now` is injectable for tests.
|
|
93
|
+
"""
|
|
94
|
+
installed = installed_version()
|
|
95
|
+
if _disabled():
|
|
96
|
+
return UpdateStatus(installed, None, False, False, False, True, None)
|
|
97
|
+
|
|
98
|
+
ts = _now(now)
|
|
99
|
+
state = _load_state()
|
|
100
|
+
|
|
101
|
+
if not force and _snoozed(state, ts):
|
|
102
|
+
latest = state.get("latest")
|
|
103
|
+
return UpdateStatus(installed, latest, _gt(latest, installed), False, True, False, None)
|
|
104
|
+
|
|
105
|
+
if not force and _checked_recently(state, ts):
|
|
106
|
+
latest = state.get("latest")
|
|
107
|
+
available = _gt(latest, installed)
|
|
108
|
+
# reuse the release notes cached from the last real check — no network on this path
|
|
109
|
+
notes = state.get("notes") if available else None
|
|
110
|
+
return _status(installed, latest, available, checked=False, notes=notes)
|
|
111
|
+
|
|
112
|
+
latest = _fetch_latest()
|
|
113
|
+
if latest is None:
|
|
114
|
+
# network failed — say nothing, don't rewrite last_checked so we retry next time
|
|
115
|
+
return UpdateStatus(installed, state.get("latest"), False, False, False, False, None)
|
|
116
|
+
|
|
117
|
+
available = _gt(latest, installed)
|
|
118
|
+
notes = _fetch_release_notes() if available else None
|
|
119
|
+
state["latest"] = latest
|
|
120
|
+
state["last_checked"] = ts
|
|
121
|
+
state["notes"] = notes
|
|
122
|
+
_save_state(state)
|
|
123
|
+
return _status(installed, latest, available, checked=True, notes=notes)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _status(installed, latest, available, *, checked, notes):
|
|
127
|
+
return UpdateStatus(
|
|
128
|
+
installed=installed,
|
|
129
|
+
latest=latest,
|
|
130
|
+
update_available=available,
|
|
131
|
+
checked=checked,
|
|
132
|
+
snoozed=False,
|
|
133
|
+
disabled=False,
|
|
134
|
+
message=_nudge(installed, latest, notes) if available else None,
|
|
135
|
+
notes=notes if available else None,
|
|
136
|
+
notes_url=RELEASES_PAGE if available else None,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def snooze(days: int = DEFAULT_SNOOZE_DAYS, *, now: float | None = None) -> dict[str, Any]:
|
|
141
|
+
"""Record a 'don't ask for N days' snooze. Honored by both the CLI and the MCP tool."""
|
|
142
|
+
ts = _now(now)
|
|
143
|
+
state = _load_state()
|
|
144
|
+
state["snooze_until"] = ts + days * 24 * 60 * 60
|
|
145
|
+
_save_state(state)
|
|
146
|
+
return {"state": "snoozed", "days": days, "snooze_until": state["snooze_until"]}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _nudge(installed: str | None, latest: str | None, notes: str | None = None) -> str:
|
|
150
|
+
head = f"cfgit {latest} is available (you have {installed or 'an older version'})."
|
|
151
|
+
tail = f"Upgrade with `pip install -U cfgit`. (Set {_DISABLE_ENV}=1 to silence this.)"
|
|
152
|
+
if notes:
|
|
153
|
+
return f"{head}\nWhat's new:\n{notes}\n{tail}\nFull notes: {RELEASES_PAGE}"
|
|
154
|
+
return f"{head} {tail}"
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _fetch_release_notes() -> str | None:
|
|
158
|
+
"""Short 'what's new' excerpt from the latest GitHub release (the notes we author at release
|
|
159
|
+
time). Best-effort: any failure returns None and the nudge degrades to the plain line."""
|
|
160
|
+
try:
|
|
161
|
+
req = urllib.request.Request(
|
|
162
|
+
GITHUB_LATEST_RELEASE_URL,
|
|
163
|
+
headers={"Accept": "application/vnd.github+json", "User-Agent": "cfgit-update-check"},
|
|
164
|
+
)
|
|
165
|
+
with urllib.request.urlopen(req, timeout=_TIMEOUT_S) as resp: # noqa: S310 - fixed https URL
|
|
166
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
167
|
+
return _excerpt(str(data.get("body") or ""))
|
|
168
|
+
except (urllib.error.URLError, TimeoutError, ValueError, KeyError, OSError):
|
|
169
|
+
return None
|
|
170
|
+
except Exception: # noqa: BLE001 - notes are optional; never raise
|
|
171
|
+
return None
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _excerpt(body: str) -> str | None:
|
|
175
|
+
"""Pull the first few bullet/highlight lines out of a release body, dropping headers/blanks."""
|
|
176
|
+
lines: list[str] = []
|
|
177
|
+
for raw in body.splitlines():
|
|
178
|
+
line = raw.strip()
|
|
179
|
+
if not line or line.startswith("#"):
|
|
180
|
+
continue
|
|
181
|
+
# normalize common markdown bullets to a plain dash
|
|
182
|
+
if line[:2] in ("- ", "* ", "• "):
|
|
183
|
+
line = " • " + line[2:].strip()
|
|
184
|
+
elif not line.startswith(("•", " •")):
|
|
185
|
+
line = " " + line
|
|
186
|
+
lines.append(line)
|
|
187
|
+
if len(lines) >= _NOTES_MAX_LINES:
|
|
188
|
+
break
|
|
189
|
+
return "\n".join(lines) if lines else None
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _disabled() -> bool:
|
|
193
|
+
return os.environ.get(_DISABLE_ENV, "") not in ("", "0", "false", "no")
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def _fetch_latest() -> str | None:
|
|
197
|
+
try:
|
|
198
|
+
req = urllib.request.Request(PYPI_URL, headers={"Accept": "application/json"})
|
|
199
|
+
with urllib.request.urlopen(req, timeout=_TIMEOUT_S) as resp: # noqa: S310 - fixed https URL
|
|
200
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
201
|
+
return str(data["info"]["version"])
|
|
202
|
+
except (urllib.error.URLError, TimeoutError, ValueError, KeyError, OSError):
|
|
203
|
+
return None
|
|
204
|
+
except Exception: # noqa: BLE001 - update check must never raise
|
|
205
|
+
return None
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def _load_state() -> dict[str, Any]:
|
|
209
|
+
try:
|
|
210
|
+
return json.loads(STATE_FILE.read_text(encoding="utf-8"))
|
|
211
|
+
except (FileNotFoundError, ValueError, OSError):
|
|
212
|
+
return {}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _save_state(state: dict[str, Any]) -> None:
|
|
216
|
+
try:
|
|
217
|
+
STATE_DIR.mkdir(parents=True, exist_ok=True)
|
|
218
|
+
STATE_FILE.write_text(json.dumps(state, indent=2), encoding="utf-8")
|
|
219
|
+
except OSError:
|
|
220
|
+
pass # can't persist (read-only home, etc.) — degrade to "check every time", never error
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def _snoozed(state: dict[str, Any], ts: float) -> bool:
|
|
224
|
+
until = state.get("snooze_until")
|
|
225
|
+
return isinstance(until, (int, float)) and ts < until
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def _checked_recently(state: dict[str, Any], ts: float) -> bool:
|
|
229
|
+
last = state.get("last_checked")
|
|
230
|
+
return isinstance(last, (int, float)) and (ts - last) < CHECK_INTERVAL_S
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _now(now: float | None) -> float:
|
|
234
|
+
if now is not None:
|
|
235
|
+
return now
|
|
236
|
+
import time
|
|
237
|
+
|
|
238
|
+
return time.time()
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _gt(latest: str | None, installed: str | None) -> bool:
|
|
242
|
+
"""Is `latest` a strictly newer release than `installed`? Tolerant PEP 440-ish compare."""
|
|
243
|
+
if not latest or not installed:
|
|
244
|
+
return False
|
|
245
|
+
try:
|
|
246
|
+
from packaging.version import Version
|
|
247
|
+
|
|
248
|
+
return Version(latest) > Version(installed)
|
|
249
|
+
except Exception: # noqa: BLE001 - packaging may be absent; fall back to a tuple compare
|
|
250
|
+
return _parse(latest) > _parse(installed)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _parse(v: str) -> tuple[int, ...]:
|
|
254
|
+
parts: list[int] = []
|
|
255
|
+
for chunk in v.split("."):
|
|
256
|
+
num = ""
|
|
257
|
+
for ch in chunk:
|
|
258
|
+
if ch.isdigit():
|
|
259
|
+
num += ch
|
|
260
|
+
else:
|
|
261
|
+
break
|
|
262
|
+
parts.append(int(num) if num else 0)
|
|
263
|
+
return tuple(parts)
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Copyright 2026 Mohammad Ausaf. Licensed under the Apache License, Version 2.0.
|
|
2
|
+
"""Update-check engine: throttle, snooze, kill switch, fail-silent, version compare."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from cfg import update
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@pytest.fixture(autouse=True)
|
|
13
|
+
def isolate_state(tmp_path, monkeypatch):
|
|
14
|
+
"""Point the state file at a temp dir, clear the kill switch, and stub the GitHub notes
|
|
15
|
+
fetch so tests never hit the network by default."""
|
|
16
|
+
monkeypatch.setattr(update, "STATE_DIR", tmp_path)
|
|
17
|
+
monkeypatch.setattr(update, "STATE_FILE", tmp_path / "update-check.json")
|
|
18
|
+
monkeypatch.delenv(update._DISABLE_ENV, raising=False)
|
|
19
|
+
monkeypatch.setattr(update, "_fetch_release_notes", lambda: " • new stuff")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _fixed_latest(value):
|
|
23
|
+
return lambda: value
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# --- version compare ------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_gt_numeric_and_equal():
|
|
30
|
+
assert update._gt("0.4.0", "0.3.0") is True
|
|
31
|
+
assert update._gt("0.10.0", "0.9.0") is True # not string-compared
|
|
32
|
+
assert update._gt("1.0.0", "0.9.9") is True
|
|
33
|
+
assert update._gt("0.3.0", "0.3.0") is False
|
|
34
|
+
assert update._gt("0.3.0", "0.4.0") is False
|
|
35
|
+
assert update._gt(None, "0.3.0") is False
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# --- core check behavior --------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_update_available_produces_message(monkeypatch):
|
|
42
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
43
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest("0.4.0"))
|
|
44
|
+
st = update.check(now=1000.0)
|
|
45
|
+
assert st.update_available is True
|
|
46
|
+
assert st.latest == "0.4.0"
|
|
47
|
+
assert st.message and "0.4.0" in st.message and "pip install -U cfgit" in st.message
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_no_update_no_message(monkeypatch):
|
|
51
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.4.0")
|
|
52
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest("0.4.0"))
|
|
53
|
+
st = update.check(now=1000.0)
|
|
54
|
+
assert st.update_available is False
|
|
55
|
+
assert st.message is None
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def test_kill_switch_disables_without_network(monkeypatch):
|
|
59
|
+
monkeypatch.setenv(update._DISABLE_ENV, "1")
|
|
60
|
+
called = {"n": 0}
|
|
61
|
+
monkeypatch.setattr(update, "_fetch_latest", lambda: called.__setitem__("n", called["n"] + 1))
|
|
62
|
+
st = update.check(now=1000.0)
|
|
63
|
+
assert st.disabled is True
|
|
64
|
+
assert st.message is None
|
|
65
|
+
assert called["n"] == 0 # never hit the network
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_throttle_skips_refetch_within_a_day(monkeypatch):
|
|
69
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
70
|
+
calls = {"n": 0}
|
|
71
|
+
|
|
72
|
+
def counting():
|
|
73
|
+
calls["n"] += 1
|
|
74
|
+
return "0.4.0"
|
|
75
|
+
|
|
76
|
+
monkeypatch.setattr(update, "_fetch_latest", counting)
|
|
77
|
+
update.check(now=1000.0) # first: fetches
|
|
78
|
+
update.check(now=1000.0 + 3600) # +1h: throttled, no fetch
|
|
79
|
+
assert calls["n"] == 1
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_force_bypasses_throttle(monkeypatch):
|
|
83
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
84
|
+
calls = {"n": 0}
|
|
85
|
+
monkeypatch.setattr(update, "_fetch_latest", lambda: (calls.__setitem__("n", calls["n"] + 1), "0.4.0")[1])
|
|
86
|
+
update.check(now=1000.0)
|
|
87
|
+
update.check(now=1000.0 + 3600, force=True)
|
|
88
|
+
assert calls["n"] == 2
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_snooze_silences_until_it_lapses(monkeypatch):
|
|
92
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
93
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest("0.4.0"))
|
|
94
|
+
update.check(now=1000.0) # populates latest
|
|
95
|
+
update.snooze(30, now=1000.0)
|
|
96
|
+
st = update.check(now=1000.0 + 5 * 24 * 3600) # 5 days later, still snoozed
|
|
97
|
+
assert st.snoozed is True
|
|
98
|
+
assert st.message is None
|
|
99
|
+
later = update.check(now=1000.0 + 40 * 24 * 3600) # 40 days later, lapsed
|
|
100
|
+
assert later.snoozed is False
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_network_failure_is_silent(monkeypatch):
|
|
104
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
105
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest(None))
|
|
106
|
+
st = update.check(now=1000.0)
|
|
107
|
+
assert st.checked is False
|
|
108
|
+
assert st.message is None
|
|
109
|
+
assert st.update_available is False
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_state_io_tolerates_garbage_file(monkeypatch):
|
|
113
|
+
update.STATE_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
114
|
+
update.STATE_FILE.write_text("not json{{{", encoding="utf-8")
|
|
115
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
116
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest("0.4.0"))
|
|
117
|
+
st = update.check(now=1000.0) # must not raise
|
|
118
|
+
assert st.update_available is True
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def test_snooze_persists_to_state_file(monkeypatch):
|
|
122
|
+
update.snooze(30, now=1000.0)
|
|
123
|
+
saved = json.loads(update.STATE_FILE.read_text())
|
|
124
|
+
assert saved["snooze_until"] == 1000.0 + 30 * 24 * 3600
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# --- what's-new release notes ---------------------------------------------------------------
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_message_includes_whats_new_notes(monkeypatch):
|
|
131
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
132
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest("0.4.0"))
|
|
133
|
+
monkeypatch.setattr(update, "_fetch_release_notes", lambda: " • cfg export\n • bulk --dry-run")
|
|
134
|
+
st = update.check(now=1000.0)
|
|
135
|
+
assert st.notes and "cfg export" in st.notes
|
|
136
|
+
assert "What's new:" in st.message and "cfg export" in st.message
|
|
137
|
+
assert st.notes_url == update.RELEASES_PAGE
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_notes_fetch_failure_degrades_to_plain_nudge(monkeypatch):
|
|
141
|
+
monkeypatch.setattr(update, "installed_version", lambda: "0.3.0")
|
|
142
|
+
monkeypatch.setattr(update, "_fetch_latest", _fixed_latest("0.4.0"))
|
|
143
|
+
monkeypatch.setattr(update, "_fetch_release_notes", lambda: None)
|
|
144
|
+
st = update.check(now=1000.0)
|
|
145
|
+
assert st.update_available is True
|
|
146
|
+
assert st.notes is None
|
|
147
|
+
assert "What's new" not in st.message # plain one-liner still works
|
|
148
|
+
assert "pip install -U cfgit" in st.message
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_excerpt_caps_lines_and_strips_headers():
|
|
152
|
+
body = "## Highlights\n\n- one\n- two\n- three\n- four\n- five\n- six\n- seven"
|
|
153
|
+
out = update._excerpt(body)
|
|
154
|
+
assert out.count("\n") + 1 == update._NOTES_MAX_LINES # capped
|
|
155
|
+
assert "Highlights" not in out
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# --- CLI nudge gating (the safety contract: humans see it, scripts never do) ----------------
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
@pytest.mark.parametrize(
|
|
162
|
+
"cmd,json_mode,isatty,expect_nudge",
|
|
163
|
+
[
|
|
164
|
+
("status", False, True, True), # interactive human read cmd → nudge
|
|
165
|
+
("doctor", False, True, True), # another read cmd → nudge
|
|
166
|
+
("status", False, False, False), # piped (non-TTY) → silent (scripts unaffected)
|
|
167
|
+
("status", True, True, False), # --json → silent (agent JSON unpolluted)
|
|
168
|
+
("commit", False, True, False), # write command → never (not in front of a mutation)
|
|
169
|
+
("set", False, True, False), # write command → never
|
|
170
|
+
],
|
|
171
|
+
)
|
|
172
|
+
def test_cli_nudge_gating(monkeypatch, capsys, cmd, json_mode, isatty, expect_nudge):
|
|
173
|
+
import types
|
|
174
|
+
|
|
175
|
+
from cfg.cli import main as m
|
|
176
|
+
|
|
177
|
+
# force an update to be "available" so the nudge WOULD fire if allowed. `_maybe_update_nudge`
|
|
178
|
+
# does `from cfg import update` internally, so patching update.check on the module suffices.
|
|
179
|
+
monkeypatch.setattr(
|
|
180
|
+
update, "check",
|
|
181
|
+
lambda *a, **k: types.SimpleNamespace(message="cfgit 9.9.9 is available!"),
|
|
182
|
+
)
|
|
183
|
+
monkeypatch.setattr(m.sys.stdout, "isatty", lambda: isatty, raising=False)
|
|
184
|
+
|
|
185
|
+
m._maybe_update_nudge(types.SimpleNamespace(cmd=cmd, json=json_mode))
|
|
186
|
+
|
|
187
|
+
captured = capsys.readouterr()
|
|
188
|
+
assert ("available" in captured.err) is expect_nudge
|
|
189
|
+
assert captured.out == "" # the nudge must NEVER touch stdout, in any case
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|