robo-cortex 0.6.2__tar.gz → 0.7.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.
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/CHANGELOG.md +6 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/PKG-INFO +1 -1
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/schema.sql +3 -3
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/__init__.py +1 -1
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/evidence.py +1 -1
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/memory.py +2 -2
- robo_cortex-0.7.0/src/robo_cortex/migrations/0004_widen_statement_limits.sql +106 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_init.py +1 -1
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_record.py +1 -1
- robo_cortex-0.7.0/tests/test_db.py +165 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_evidence.py +2 -2
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_init.py +1 -1
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_memory.py +2 -2
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_record_batch.py +2 -2
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_smoke.py +1 -1
- robo_cortex-0.6.2/tests/test_db.py +0 -78
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/.gitignore +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/LICENSE +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/README.md +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/pyproject.toml +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/__init__.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/__main__.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/_common.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/_output.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/app.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/__init__.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/affected.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/completion.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/evidence.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/hooks.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/init.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/link.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/list_cmd.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/mcp.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/record.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/retrieve.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/search.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/show.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/status.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/cli/commands/transfer.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/__init__.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/assumptions.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/db.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/errors.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/git.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/hooks.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/init.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/invalidate.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/lifecycle.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/retrieve.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/semantic.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/store.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/text.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/core/transfer.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/gitea.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/mcp_server.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/migrations/0001_init.sql +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/migrations/0002_add_usage_tracking.sql +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/migrations/0003_add_meta_table.sql +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/sdk.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/__init__.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/conftest.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/fixtures.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_add_path.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_affected.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_assumptions.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_affected.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_global_no_repo.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_lifecycle.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_retrieve.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_cli_scope_b.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_completion.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_curation.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_gitea.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_hooks.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_invalidate.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_lifecycle.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_mcp_contracts.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_mcp_stdio.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_output.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_retrieve.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_reverify.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_scope_b.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_sdk.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_sdk_global_no_repo.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_search.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_semantic.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_transfer.py +0 -0
- {robo_cortex-0.6.2 → robo_cortex-0.7.0}/tests/test_update_path.py +0 -0
|
@@ -4,6 +4,12 @@ All notable changes to this project are documented here. Format loosely follows
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.7.0] — 2026-11-04
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **`statement`/`assumptions`/evidence `description` caps raised from 500 to 750 characters.** Revisits the 2026-08-31 decision to hold the line at 500 (roco's terseness was deliberate, and dimag already routes longer content elsewhere) — the migration mechanism to change a SQLite CHECK constraint (create-copy-drop-rename table rebuild) was proven safe against a populated fixture DB back then but never actually shipped as a real migration. New `migrations/0004_widen_statement_limits.sql` rebuilds `memory` and `evidence` with the wider caps, preserving every row, `memory_path`/`evidence`/`memory_link` foreign keys, the FTS5 index, and the AUTOINCREMENT sequence (reseeded explicitly — a table-rebuild loses `sqlite_sequence`'s row for the old table name). `--statement`/`--why`/`--assumptions` CLI help text updates automatically (sourced from the same constants). Covered by a new `test_db.py` case that upgrades a populated version-3 database and checks FK integrity, row survival, and FTS lookup post-migration.
|
|
12
|
+
|
|
7
13
|
## [0.6.1] — 2026-08-10
|
|
8
14
|
|
|
9
15
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: robo-cortex
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Long-term memory system for LLM coding agents working inside a Git repository
|
|
5
5
|
Project-URL: Homepage, https://robotel.top
|
|
6
6
|
Project-URL: Repository, https://github.com/robotel-limited/robo-cortex
|
|
@@ -10,9 +10,9 @@ CREATE TABLE memory (
|
|
|
10
10
|
('fact', 'decision', 'convention', 'hypothesis',
|
|
11
11
|
'experiment', 'lesson', 'open_question')),
|
|
12
12
|
scope TEXT NOT NULL CHECK (scope IN ('repo', 'global')),
|
|
13
|
-
statement TEXT NOT NULL CHECK (length(statement) <=
|
|
13
|
+
statement TEXT NOT NULL CHECK (length(statement) <= 750 AND length(statement) > 0),
|
|
14
14
|
why_it_matters TEXT CHECK (why_it_matters IS NULL OR length(why_it_matters) <= 300),
|
|
15
|
-
assumptions TEXT CHECK (assumptions IS NULL OR length(assumptions) <=
|
|
15
|
+
assumptions TEXT CHECK (assumptions IS NULL OR length(assumptions) <= 750),
|
|
16
16
|
status TEXT NOT NULL DEFAULT 'provisional' CHECK (status IN
|
|
17
17
|
('active', 'provisional', 'needs_review', 'superseded',
|
|
18
18
|
'invalidated', 'abandoned', 'archived')),
|
|
@@ -44,7 +44,7 @@ CREATE TABLE evidence (
|
|
|
44
44
|
kind TEXT NOT NULL CHECK (kind IN
|
|
45
45
|
('test_output', 'ci', 'commit', 'gitea_pr', 'gitea_issue',
|
|
46
46
|
'free_text', 'cold_storage_ref')),
|
|
47
|
-
description TEXT NOT NULL CHECK (length(description) <=
|
|
47
|
+
description TEXT NOT NULL CHECK (length(description) <= 750 AND length(description) > 0),
|
|
48
48
|
command TEXT,
|
|
49
49
|
expected_outcome TEXT,
|
|
50
50
|
ref TEXT,
|
|
@@ -7,7 +7,7 @@ EVIDENCE_KINDS = {
|
|
|
7
7
|
"test_output", "ci", "commit", "gitea_pr", "gitea_issue",
|
|
8
8
|
"free_text", "cold_storage_ref",
|
|
9
9
|
}
|
|
10
|
-
DESCRIPTION_MAX =
|
|
10
|
+
DESCRIPTION_MAX = 750
|
|
11
11
|
|
|
12
12
|
# ARCHITECTURE.md §3.1 -- mechanical, not judged: count and kind only.
|
|
13
13
|
EVIDENCE_KIND_WEIGHTS = {
|
|
@@ -14,9 +14,9 @@ TYPES = {
|
|
|
14
14
|
SCOPES = {"repo", "global"}
|
|
15
15
|
CONFIDENCES = {"low", "medium", "high"}
|
|
16
16
|
|
|
17
|
-
STATEMENT_MAX =
|
|
17
|
+
STATEMENT_MAX = 750
|
|
18
18
|
WHY_IT_MATTERS_MAX = 300
|
|
19
|
-
ASSUMPTIONS_MAX =
|
|
19
|
+
ASSUMPTIONS_MAX = 750
|
|
20
20
|
|
|
21
21
|
# Live working knowledge vs. final/terminal history -- shared by retrieve.py
|
|
22
22
|
# (ranking candidate set) and invalidate.py (what the staleness refresh and
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
-- Migration 0004: widen statement/assumptions/description caps 500 -> 750.
|
|
2
|
+
-- SQLite has no ALTER TABLE for a CHECK constraint, so this is the
|
|
3
|
+
-- create-copy-drop-rename rebuild documented in db.py's migrate() -- the
|
|
4
|
+
-- runner already disables foreign_keys for the duration and verifies with
|
|
5
|
+
-- PRAGMA foreign_key_check afterward, so this script only has to recreate
|
|
6
|
+
-- everything the old `memory`/`evidence` tables carried: all columns
|
|
7
|
+
-- (including `use_count`/`last_used_at`, added after 0001 by
|
|
8
|
+
-- 0002_add_usage_tracking.sql -- a rebuild must restate every column ever
|
|
9
|
+
-- added since init, not just 0001_init.sql's original set), indexes, the
|
|
10
|
+
-- AUTOINCREMENT sequence (sqlite_sequence is keyed by table name and does
|
|
11
|
+
-- NOT follow a RENAME+DROP, so it must be reseeded explicitly or a future
|
|
12
|
+
-- insert on either table could reuse an id still referenced by memory_path/
|
|
13
|
+
-- evidence/memory_link), and memory's FTS5 triggers (trigger objects are
|
|
14
|
+
-- dropped along with the table they're defined ON, same as indexes).
|
|
15
|
+
|
|
16
|
+
CREATE TABLE memory_new (
|
|
17
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
18
|
+
type TEXT NOT NULL CHECK (type IN
|
|
19
|
+
('fact', 'decision', 'convention', 'hypothesis',
|
|
20
|
+
'experiment', 'lesson', 'open_question')),
|
|
21
|
+
scope TEXT NOT NULL CHECK (scope IN ('repo', 'global')),
|
|
22
|
+
statement TEXT NOT NULL CHECK (length(statement) <= 750 AND length(statement) > 0),
|
|
23
|
+
why_it_matters TEXT CHECK (why_it_matters IS NULL OR length(why_it_matters) <= 300),
|
|
24
|
+
assumptions TEXT CHECK (assumptions IS NULL OR length(assumptions) <= 750),
|
|
25
|
+
status TEXT NOT NULL DEFAULT 'provisional' CHECK (status IN
|
|
26
|
+
('active', 'provisional', 'needs_review', 'superseded',
|
|
27
|
+
'invalidated', 'abandoned', 'archived')),
|
|
28
|
+
status_reason TEXT,
|
|
29
|
+
pre_review_status TEXT CHECK (pre_review_status IS NULL OR pre_review_status IN
|
|
30
|
+
('active', 'provisional')),
|
|
31
|
+
confidence TEXT NOT NULL CHECK (confidence IN ('low', 'medium', 'high')),
|
|
32
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
33
|
+
last_verified_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
34
|
+
created_by TEXT,
|
|
35
|
+
use_count INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
last_used_at TEXT
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
INSERT INTO memory_new SELECT * FROM memory;
|
|
40
|
+
|
|
41
|
+
CREATE TABLE evidence_new (
|
|
42
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
43
|
+
memory_id INTEGER NOT NULL REFERENCES memory_new(id) ON DELETE CASCADE,
|
|
44
|
+
kind TEXT NOT NULL CHECK (kind IN
|
|
45
|
+
('test_output', 'ci', 'commit', 'gitea_pr', 'gitea_issue',
|
|
46
|
+
'free_text', 'cold_storage_ref')),
|
|
47
|
+
description TEXT NOT NULL CHECK (length(description) <= 750 AND length(description) > 0),
|
|
48
|
+
command TEXT,
|
|
49
|
+
expected_outcome TEXT,
|
|
50
|
+
ref TEXT,
|
|
51
|
+
status TEXT NOT NULL DEFAULT 'unverified' CHECK (status IN
|
|
52
|
+
('unverified', 'verified', 'unverifiable')),
|
|
53
|
+
created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
|
|
54
|
+
checked_at TEXT
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
INSERT INTO evidence_new SELECT * FROM evidence;
|
|
58
|
+
|
|
59
|
+
DROP TABLE evidence;
|
|
60
|
+
DROP TABLE memory;
|
|
61
|
+
ALTER TABLE memory_new RENAME TO memory;
|
|
62
|
+
ALTER TABLE evidence_new RENAME TO evidence;
|
|
63
|
+
|
|
64
|
+
-- memory_path and memory_link's own FK references (declared `REFERENCES
|
|
65
|
+
-- memory(id)`) are resolved by name at use time, not bound to the old
|
|
66
|
+
-- table object, so they automatically target the rebuilt `memory` table --
|
|
67
|
+
-- nothing to redo for those two tables.
|
|
68
|
+
|
|
69
|
+
CREATE INDEX idx_memory_scope_status ON memory (scope, status);
|
|
70
|
+
CREATE INDEX idx_evidence_memory_id ON evidence (memory_id);
|
|
71
|
+
|
|
72
|
+
-- Reseed sqlite_sequence: a bare INSERT INTO ... SELECT * (explicit ids)
|
|
73
|
+
-- does not update it, and the rebuilt tables start with no row of their
|
|
74
|
+
-- own, so the next AUTOINCREMENT insert would start from 1 and could
|
|
75
|
+
-- collide with an id still referenced by memory_path/evidence/memory_link.
|
|
76
|
+
DELETE FROM sqlite_sequence WHERE name IN ('memory', 'evidence', 'memory_new', 'evidence_new');
|
|
77
|
+
INSERT INTO sqlite_sequence (name, seq)
|
|
78
|
+
SELECT 'memory', COALESCE((SELECT MAX(id) FROM memory), 0);
|
|
79
|
+
INSERT INTO sqlite_sequence (name, seq)
|
|
80
|
+
SELECT 'evidence', COALESCE((SELECT MAX(id) FROM evidence), 0);
|
|
81
|
+
|
|
82
|
+
DROP TRIGGER IF EXISTS memory_fts_ai;
|
|
83
|
+
DROP TRIGGER IF EXISTS memory_fts_ad;
|
|
84
|
+
DROP TRIGGER IF EXISTS memory_fts_au;
|
|
85
|
+
|
|
86
|
+
CREATE TRIGGER memory_fts_ai AFTER INSERT ON memory BEGIN
|
|
87
|
+
INSERT INTO memory_fts (rowid, statement, why_it_matters)
|
|
88
|
+
VALUES (new.id, new.statement, new.why_it_matters);
|
|
89
|
+
END;
|
|
90
|
+
|
|
91
|
+
CREATE TRIGGER memory_fts_ad AFTER DELETE ON memory BEGIN
|
|
92
|
+
INSERT INTO memory_fts (memory_fts, rowid, statement, why_it_matters)
|
|
93
|
+
VALUES ('delete', old.id, old.statement, old.why_it_matters);
|
|
94
|
+
END;
|
|
95
|
+
|
|
96
|
+
CREATE TRIGGER memory_fts_au AFTER UPDATE ON memory BEGIN
|
|
97
|
+
INSERT INTO memory_fts (memory_fts, rowid, statement, why_it_matters)
|
|
98
|
+
VALUES ('delete', old.id, old.statement, old.why_it_matters);
|
|
99
|
+
INSERT INTO memory_fts (rowid, statement, why_it_matters)
|
|
100
|
+
VALUES (new.id, new.statement, new.why_it_matters);
|
|
101
|
+
END;
|
|
102
|
+
|
|
103
|
+
-- memory_fts is an external-content FTS5 table (content='memory',
|
|
104
|
+
-- content_rowid='id'); since the rebuild preserved every row's `id`
|
|
105
|
+
-- unchanged, the existing FTS index entries still point at valid rowids --
|
|
106
|
+
-- no 'rebuild' command needed, only the triggers above for future writes.
|
|
@@ -74,7 +74,7 @@ def test_cli_record_batch_via_stdin(tmp_path):
|
|
|
74
74
|
|
|
75
75
|
payload = "\n".join([
|
|
76
76
|
json.dumps({"type": "fact", "scope": "repo", "statement": "one", "confidence": "low"}),
|
|
77
|
-
json.dumps({"type": "fact", "scope": "repo", "statement": "x" *
|
|
77
|
+
json.dumps({"type": "fact", "scope": "repo", "statement": "x" * 751, "confidence": "low"}),
|
|
78
78
|
json.dumps({"type": "fact", "scope": "repo", "statement": "two", "confidence": "high"}),
|
|
79
79
|
])
|
|
80
80
|
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import sqlite3
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from robo_cortex.core.db import MIGRATIONS_DIR, connect, current_version, execute, migrate
|
|
6
|
+
from robo_cortex.core.errors import BusyError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_migrate_from_empty_creates_schema(tmp_path):
|
|
10
|
+
conn = connect(tmp_path / "memory.db")
|
|
11
|
+
version = migrate(conn)
|
|
12
|
+
assert version == 4
|
|
13
|
+
tables = {
|
|
14
|
+
row[0]
|
|
15
|
+
for row in conn.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
|
|
16
|
+
}
|
|
17
|
+
assert {"memory", "memory_path", "evidence", "memory_link", "cold_storage"} <= tables
|
|
18
|
+
conn.close()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def test_migrate_is_idempotent_on_same_connection(tmp_path):
|
|
22
|
+
conn = connect(tmp_path / "memory.db")
|
|
23
|
+
migrate(conn)
|
|
24
|
+
version_again = migrate(conn)
|
|
25
|
+
assert version_again == 4
|
|
26
|
+
assert current_version(conn) == 4
|
|
27
|
+
conn.close()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_migrate_is_idempotent_across_reopened_connections(tmp_path):
|
|
31
|
+
db_path = tmp_path / "memory.db"
|
|
32
|
+
|
|
33
|
+
first = connect(db_path)
|
|
34
|
+
migrate(first)
|
|
35
|
+
first.close()
|
|
36
|
+
|
|
37
|
+
second = connect(db_path)
|
|
38
|
+
version = migrate(second)
|
|
39
|
+
assert version == 4
|
|
40
|
+
second.close()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_migrated_db_accepts_a_row(tmp_path):
|
|
44
|
+
conn = connect(tmp_path / "memory.db")
|
|
45
|
+
migrate(conn)
|
|
46
|
+
execute(
|
|
47
|
+
conn,
|
|
48
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
49
|
+
("fact", "repo", "The scanner batches at 50 items.", "high"),
|
|
50
|
+
)
|
|
51
|
+
row = conn.execute("SELECT statement FROM memory").fetchone()
|
|
52
|
+
assert row[0] == "The scanner batches at 50 items."
|
|
53
|
+
conn.close()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_0004_widens_limits_and_preserves_existing_rows_and_fk_integrity(tmp_path):
|
|
57
|
+
"""Upgrade path: a DB already on version 3 (pre-0004, 500-char caps),
|
|
58
|
+
carrying rows in every table 0004's rebuild touches or references
|
|
59
|
+
(memory, evidence, memory_path, memory_link), must come out of
|
|
60
|
+
`migrate()` on version 4 with those rows intact, FK-valid, and able to
|
|
61
|
+
accept a statement/description between 501 and 750 chars that version 3
|
|
62
|
+
would have rejected. Exercises the exact failure mode flagged in
|
|
63
|
+
db.py's migrate() docstring: a table-rebuild migration silently
|
|
64
|
+
cascade-deleting referencing rows if foreign_keys isn't off for the
|
|
65
|
+
rebuild.
|
|
66
|
+
"""
|
|
67
|
+
conn = connect(tmp_path / "memory.db")
|
|
68
|
+
v3_files = [p for p in sorted(MIGRATIONS_DIR.glob("*.sql")) if int(p.name.split("_", 1)[0]) <= 3]
|
|
69
|
+
for path in v3_files:
|
|
70
|
+
conn.execute("PRAGMA foreign_keys = OFF")
|
|
71
|
+
conn.executescript(f"BEGIN;\n{path.read_text()}\nPRAGMA user_version = {path.name.split('_', 1)[0]};\nCOMMIT;")
|
|
72
|
+
conn.execute("PRAGMA foreign_keys = ON")
|
|
73
|
+
assert current_version(conn) == 3
|
|
74
|
+
|
|
75
|
+
memory_id = execute(
|
|
76
|
+
conn,
|
|
77
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
78
|
+
("fact", "repo", "pre-existing memory row", "high"),
|
|
79
|
+
).lastrowid
|
|
80
|
+
execute(
|
|
81
|
+
conn,
|
|
82
|
+
"INSERT INTO memory_path (memory_id, path, blob_hash) VALUES (?, ?, ?)",
|
|
83
|
+
(memory_id, "src/thing.py", "deadbeef"),
|
|
84
|
+
)
|
|
85
|
+
evidence_id = execute(
|
|
86
|
+
conn,
|
|
87
|
+
"INSERT INTO evidence (memory_id, kind, description) VALUES (?, ?, ?)",
|
|
88
|
+
(memory_id, "free_text", "pre-existing evidence row"),
|
|
89
|
+
).lastrowid
|
|
90
|
+
other_id = execute(
|
|
91
|
+
conn,
|
|
92
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
93
|
+
("fact", "repo", "a second memory to link against", "low"),
|
|
94
|
+
).lastrowid
|
|
95
|
+
execute(
|
|
96
|
+
conn,
|
|
97
|
+
"INSERT INTO memory_link (from_id, to_id, link_type) VALUES (?, ?, ?)",
|
|
98
|
+
(memory_id, other_id, "duplicate_of"),
|
|
99
|
+
)
|
|
100
|
+
with pytest.raises(sqlite3.IntegrityError):
|
|
101
|
+
execute(
|
|
102
|
+
conn,
|
|
103
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
104
|
+
("fact", "repo", "x" * 600, "low"),
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
version = migrate(conn)
|
|
108
|
+
|
|
109
|
+
assert version == 4
|
|
110
|
+
assert conn.execute("PRAGMA foreign_key_check").fetchall() == []
|
|
111
|
+
assert conn.execute(
|
|
112
|
+
"SELECT statement FROM memory WHERE id = ?", (memory_id,)
|
|
113
|
+
).fetchone()[0] == "pre-existing memory row"
|
|
114
|
+
assert conn.execute(
|
|
115
|
+
"SELECT path FROM memory_path WHERE memory_id = ?", (memory_id,)
|
|
116
|
+
).fetchone()[0] == "src/thing.py"
|
|
117
|
+
assert conn.execute(
|
|
118
|
+
"SELECT description FROM evidence WHERE id = ?", (evidence_id,)
|
|
119
|
+
).fetchone()[0] == "pre-existing evidence row"
|
|
120
|
+
assert conn.execute(
|
|
121
|
+
"SELECT link_type FROM memory_link WHERE from_id = ? AND to_id = ?", (memory_id, other_id)
|
|
122
|
+
).fetchone()[0] == "duplicate_of"
|
|
123
|
+
assert conn.execute(
|
|
124
|
+
"SELECT statement FROM memory_fts WHERE rowid = ?", (memory_id,)
|
|
125
|
+
).fetchone()[0] == "pre-existing memory row"
|
|
126
|
+
|
|
127
|
+
new_id = execute(
|
|
128
|
+
conn,
|
|
129
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
130
|
+
("fact", "repo", "x" * 600, "low"),
|
|
131
|
+
).lastrowid
|
|
132
|
+
assert new_id > other_id
|
|
133
|
+
execute(
|
|
134
|
+
conn,
|
|
135
|
+
"INSERT INTO evidence (memory_id, kind, description) VALUES (?, ?, ?)",
|
|
136
|
+
(new_id, "free_text", "y" * 600),
|
|
137
|
+
)
|
|
138
|
+
conn.close()
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def test_busy_writer_surfaces_clear_error_not_a_stack_trace(tmp_path):
|
|
142
|
+
db_path = tmp_path / "memory.db"
|
|
143
|
+
|
|
144
|
+
setup = connect(db_path)
|
|
145
|
+
migrate(setup)
|
|
146
|
+
setup.close()
|
|
147
|
+
|
|
148
|
+
holder = connect(db_path, busy_timeout_ms=100)
|
|
149
|
+
holder.execute("BEGIN EXCLUSIVE")
|
|
150
|
+
holder.execute(
|
|
151
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
152
|
+
("fact", "repo", "held by another writer", "low"),
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
contender = connect(db_path, busy_timeout_ms=100)
|
|
156
|
+
with pytest.raises(BusyError, match="another writer is active, retry"):
|
|
157
|
+
execute(
|
|
158
|
+
contender,
|
|
159
|
+
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
160
|
+
("fact", "repo", "should be rejected", "low"),
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
holder.execute("ROLLBACK")
|
|
164
|
+
holder.close()
|
|
165
|
+
contender.close()
|
|
@@ -59,8 +59,8 @@ def test_attach_evidence_validates_kind_and_description(tmp_path):
|
|
|
59
59
|
attach_evidence(conn, repo, result["id"], kind="nonsense", description="x")
|
|
60
60
|
with pytest.raises(ValidationError, match="must not be empty"):
|
|
61
61
|
attach_evidence(conn, repo, result["id"], kind="free_text", description=" ")
|
|
62
|
-
with pytest.raises(ValidationError, match="exceeds
|
|
63
|
-
attach_evidence(conn, repo, result["id"], kind="free_text", description="x" *
|
|
62
|
+
with pytest.raises(ValidationError, match="exceeds 750"):
|
|
63
|
+
attach_evidence(conn, repo, result["id"], kind="free_text", description="x" * 751)
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
def test_evidence_strength_mechanical_not_judged(tmp_path):
|
|
@@ -15,7 +15,7 @@ def test_init_creates_cortex_dir_and_db(tmp_path):
|
|
|
15
15
|
db_path = Path(result["db_path"])
|
|
16
16
|
assert db_path.exists()
|
|
17
17
|
assert db_path.parent.name == ".cortex"
|
|
18
|
-
assert result["schema_version"] ==
|
|
18
|
+
assert result["schema_version"] == 4
|
|
19
19
|
assert Path(result["repo_root"]).resolve() == repo.resolve()
|
|
20
20
|
|
|
21
21
|
|
|
@@ -68,13 +68,13 @@ def test_record_refuses_nonexistent_path(tmp_path):
|
|
|
68
68
|
def test_record_refuses_over_length_statement(tmp_path):
|
|
69
69
|
repo, conn = _store(tmp_path)
|
|
70
70
|
|
|
71
|
-
with pytest.raises(ValidationError, match="exceeds
|
|
71
|
+
with pytest.raises(ValidationError, match="exceeds 750 characters"):
|
|
72
72
|
record_memory(
|
|
73
73
|
conn,
|
|
74
74
|
repo,
|
|
75
75
|
type="fact",
|
|
76
76
|
scope="repo",
|
|
77
|
-
statement="x" *
|
|
77
|
+
statement="x" * 751,
|
|
78
78
|
confidence="low",
|
|
79
79
|
)
|
|
80
80
|
assert list_memories(conn) == []
|
|
@@ -55,7 +55,7 @@ def test_batch_reports_each_invalid_line_and_still_records_valid_ones(tmp_path):
|
|
|
55
55
|
repo, conn = _store(tmp_path)
|
|
56
56
|
lines = [
|
|
57
57
|
_line(type="fact", scope="repo", statement="good line one", confidence="low"),
|
|
58
|
-
_line(type="fact", scope="repo", statement="x" *
|
|
58
|
+
_line(type="fact", scope="repo", statement="x" * 751, confidence="low"), # too long
|
|
59
59
|
"not even json",
|
|
60
60
|
_line(type="fact", scope="repo", statement="dead path", confidence="low",
|
|
61
61
|
paths=["does/not/exist.py"]),
|
|
@@ -67,7 +67,7 @@ def test_batch_reports_each_invalid_line_and_still_records_valid_ones(tmp_path):
|
|
|
67
67
|
assert result["created"] == 2
|
|
68
68
|
assert len(result["failed"]) == 3
|
|
69
69
|
assert result["failed"][0]["line"] == 2
|
|
70
|
-
assert "exceeds
|
|
70
|
+
assert "exceeds 750" in result["failed"][0]["error"]
|
|
71
71
|
assert result["failed"][1]["line"] == 3
|
|
72
72
|
assert "invalid JSON" in result["failed"][1]["error"]
|
|
73
73
|
assert result["failed"][2]["line"] == 4
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
|
|
3
|
-
from robo_cortex.core.db import connect, current_version, execute, migrate
|
|
4
|
-
from robo_cortex.core.errors import BusyError
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def test_migrate_from_empty_creates_schema(tmp_path):
|
|
8
|
-
conn = connect(tmp_path / "memory.db")
|
|
9
|
-
version = migrate(conn)
|
|
10
|
-
assert version == 3
|
|
11
|
-
tables = {
|
|
12
|
-
row[0]
|
|
13
|
-
for row in conn.execute("SELECT name FROM sqlite_master WHERE type = 'table'")
|
|
14
|
-
}
|
|
15
|
-
assert {"memory", "memory_path", "evidence", "memory_link", "cold_storage"} <= tables
|
|
16
|
-
conn.close()
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def test_migrate_is_idempotent_on_same_connection(tmp_path):
|
|
20
|
-
conn = connect(tmp_path / "memory.db")
|
|
21
|
-
migrate(conn)
|
|
22
|
-
version_again = migrate(conn)
|
|
23
|
-
assert version_again == 3
|
|
24
|
-
assert current_version(conn) == 3
|
|
25
|
-
conn.close()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def test_migrate_is_idempotent_across_reopened_connections(tmp_path):
|
|
29
|
-
db_path = tmp_path / "memory.db"
|
|
30
|
-
|
|
31
|
-
first = connect(db_path)
|
|
32
|
-
migrate(first)
|
|
33
|
-
first.close()
|
|
34
|
-
|
|
35
|
-
second = connect(db_path)
|
|
36
|
-
version = migrate(second)
|
|
37
|
-
assert version == 3
|
|
38
|
-
second.close()
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def test_migrated_db_accepts_a_row(tmp_path):
|
|
42
|
-
conn = connect(tmp_path / "memory.db")
|
|
43
|
-
migrate(conn)
|
|
44
|
-
execute(
|
|
45
|
-
conn,
|
|
46
|
-
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
47
|
-
("fact", "repo", "The scanner batches at 50 items.", "high"),
|
|
48
|
-
)
|
|
49
|
-
row = conn.execute("SELECT statement FROM memory").fetchone()
|
|
50
|
-
assert row[0] == "The scanner batches at 50 items."
|
|
51
|
-
conn.close()
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def test_busy_writer_surfaces_clear_error_not_a_stack_trace(tmp_path):
|
|
55
|
-
db_path = tmp_path / "memory.db"
|
|
56
|
-
|
|
57
|
-
setup = connect(db_path)
|
|
58
|
-
migrate(setup)
|
|
59
|
-
setup.close()
|
|
60
|
-
|
|
61
|
-
holder = connect(db_path, busy_timeout_ms=100)
|
|
62
|
-
holder.execute("BEGIN EXCLUSIVE")
|
|
63
|
-
holder.execute(
|
|
64
|
-
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
65
|
-
("fact", "repo", "held by another writer", "low"),
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
contender = connect(db_path, busy_timeout_ms=100)
|
|
69
|
-
with pytest.raises(BusyError, match="another writer is active, retry"):
|
|
70
|
-
execute(
|
|
71
|
-
contender,
|
|
72
|
-
"INSERT INTO memory (type, scope, statement, confidence) VALUES (?, ?, ?, ?)",
|
|
73
|
-
("fact", "repo", "should be rejected", "low"),
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
holder.execute("ROLLBACK")
|
|
77
|
-
holder.close()
|
|
78
|
-
contender.close()
|
|
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
|
{robo_cortex-0.6.2 → robo_cortex-0.7.0}/src/robo_cortex/migrations/0002_add_usage_tracking.sql
RENAMED
|
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
|