Commit 5f2ad4c
* feat(http): migrate read path to adapter layer (#261)
Spec #258 isolated markdown internals (SpecLoader, SpecInfo, SpecWriter,
SpecArchiver, …) behind a module boundary and left leanspec-http
intentionally broken as a compiler-guided migration map. This change
implements the read-path portion of that migration per spec #261:
- types/specs.rs: SpecSummary/SpecDetail now build from &SpecDoc using
schema semantic hints (status, priority, tags, assignee) rather than
the old SpecInfo frontmatter struct.
- handlers/specs/helpers.rs: get_loader_and_project replaced with
get_adapter_and_project returning Box<dyn Adapter>, plus shared
helpers for AdapterError → HTTP mapping and a markdown-adapter guard.
- handlers/specs/read.rs: list / get / search / raw / sub-spec read
handlers go through adapter.list() and adapter.get(). Hierarchy and
required_by are computed from SpecDoc.links instead of the markdown
loader's relationship index.
- handlers/specs/compute.rs: stats group by semantic-hint fields on
SpecDoc; dependencies and per-spec validation now return HTTP 422
with a clear error when the active adapter is not markdown.
- watcher.rs / state.rs: the file watcher holds a typed
Arc<MarkdownAdapter> per project for cache invalidation and only
activates for projects whose adapter resolves to markdown.
- handlers/adapter.rs: adds GET /api/projects/{id}/schema returning
the active adapter's SpecSchema as JSON so the UI can render dynamic
field sets.
Write handlers (create / metadata / raw / checklist / batch) are
migrated minimally to the adapter API so the crate compiles — they
keep using leanspec_core::adapters::markdown::{SpecInfo, SpecStatus,
SpecFrontmatter} via the public markdown module path for transition
checks, umbrella completion verification, and template rendering.
Full fetch-transform-push migration of those handlers lives in #262.
Tests: cargo test -p leanspec-http (102 passing), cargo clippy
-p leanspec-http -- -D warnings, cargo fmt -- --check all green.
Closes #261
* fix(http): address review feedback on adapter migration
Copilot review on #289 flagged seven issues; the substantive ones are fixed
here:
* Path traversal in `resolve_markdown_spec_path`: spec ids containing `..`,
path separators, or absolute paths now return None instead of joining
outside the specs root. Same `invalid_spec_id` guard rejects malicious
names in `create_project_spec` so they can't write outside `specs_dir`.
* `file_path` regression on markdown list/search responses: SpecDoc.url is
None for the markdown adapter, so list summaries had empty `file_path`.
A new `populate_file_path` helper falls back to the on-disk README path
for markdown projects so the field round-trips like before.
* Cycle detection in `build_hierarchy`: parent links forming a cycle (A→B,
B→A) would recurse forever. The walker now carries a visited set and
short-circuits when a spec is re-entered, so a malformed dataset can no
longer stack-overflow the server.
* Relative `settings.directory` resolution: a markdown adapter config with
`directory: specs` was being resolved against the server CWD rather than
the project root. New `adapter_resolution.rs` module normalises relative
paths against `project_root` before instantiating the adapter, so the
`/specs`, `/adapter`, and `/schema` endpoints all agree on the right
spec tree.
* Duplicated adapter config candidate list: `state.rs` had its own copy of
the YAML candidate paths. Both watcher and handlers now share
`adapter_resolution::ADAPTER_CONFIG_CANDIDATES`/`find_adapter_config`,
so watcher activation can't drift from request-time resolution.
* Fuzzy spec id match in `resolve_markdown_spec_path`: the old `contains`
heuristic would resolve `01` onto `001-foo` or `foo` onto `bar-foo-baz`.
Tightened to numeric-prefix or slug-suffix exact match against the
directory's `<NNN>-<slug>` shape.
Added unit tests cover: `invalid_spec_id` rejecting traversal, fuzzy
matching boundaries, `build_hierarchy` terminating on a parent cycle, and
the new adapter-resolution behaviour (fallback, relative→absolute,
absolute preserved, non-markdown left alone).
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6fef741 commit 5f2ad4c
13 files changed
Lines changed: 1841 additions & 890 deletions
File tree
- rust/leanspec-http
- src
- handlers
- specs
- types
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | | - | |
| 12 | + | |
| 13 | + | |
15 | 14 | | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | 20 | | |
52 | 21 | | |
53 | 22 | | |
| |||
61 | 30 | | |
62 | 31 | | |
63 | 32 | | |
64 | | - | |
| 33 | + | |
65 | 34 | | |
66 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
0 commit comments