hub-project-from-path.test.mjs
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠ breaking
11 days ago
| 1 | /** |
| 2 | * Contract for vault path → project slug (mirrors web/hub/hub.js projectSlugFromProjectsPath). |
| 3 | */ |
| 4 | import { describe, it } from 'node:test'; |
| 5 | import assert from 'node:assert'; |
| 6 | |
| 7 | function projectSlugFromProjectsPath(path) { |
| 8 | if (!path || typeof path !== 'string') return null; |
| 9 | const m = path.match(/^projects\/([^/]+)(?:\/|$)/); |
| 10 | return m ? m[1] : null; |
| 11 | } |
| 12 | |
| 13 | function projectsPathTypoSuggestion(path) { |
| 14 | const p = String(path || '').trim(); |
| 15 | if (!p) return null; |
| 16 | if (/^project\//.test(p) && !/^projects\//.test(p)) return p.replace(/^project\//, 'projects/'); |
| 17 | return null; |
| 18 | } |
| 19 | |
| 20 | describe('project slug from projects/… vault paths', () => { |
| 21 | it('returns first segment after projects/', () => { |
| 22 | assert.strictEqual(projectSlugFromProjectsPath('projects/foo/inbox/x.md'), 'foo'); |
| 23 | assert.strictEqual(projectSlugFromProjectsPath('projects/bar-baz/note.md'), 'bar-baz'); |
| 24 | }); |
| 25 | |
| 26 | it('returns null when not under projects/', () => { |
| 27 | assert.strictEqual(projectSlugFromProjectsPath('inbox/x.md'), null); |
| 28 | assert.strictEqual(projectSlugFromProjectsPath('deep/projects/no.md'), null); |
| 29 | assert.strictEqual(projectSlugFromProjectsPath(null), null); |
| 30 | }); |
| 31 | |
| 32 | it('treats projects/foo.md as segment foo.md (single path component)', () => { |
| 33 | assert.strictEqual(projectSlugFromProjectsPath('projects/foo.md'), 'foo.md'); |
| 34 | }); |
| 35 | }); |
| 36 | |
| 37 | describe('projects/ vs project/ typo fix suggestion', () => { |
| 38 | it('rewrites project/ prefix to projects/', () => { |
| 39 | assert.strictEqual(projectsPathTypoSuggestion('project/acme/inbox/x.md'), 'projects/acme/inbox/x.md'); |
| 40 | }); |
| 41 | |
| 42 | it('does not rewrite valid projects/ paths', () => { |
| 43 | assert.strictEqual(projectsPathTypoSuggestion('projects/acme/inbox/x.md'), null); |
| 44 | }); |
| 45 | |
| 46 | it('does not treat unrelated paths as typos', () => { |
| 47 | assert.strictEqual(projectsPathTypoSuggestion('inbox/x.md'), null); |
| 48 | assert.strictEqual(projectsPathTypoSuggestion('deep/project/file.md'), null); |
| 49 | }); |
| 50 | }); |
File History
4 commits
sha256:b5f647cb9c409f563d4671fe3fc05ddea01fabfed9b41fc11cb923588e1c1baf
mirror: GitHub Phase A durable MCP OAuth (#270)
Human
minor
⚠
11 days ago
sha256:d8c648b20a4d53b2673c5c082ee7edfa7b2fc9b11080832da1f38807b6bf940b
fix(7C-L1b): route hosted delegation proposals through cani…
Human
minor
⚠
31 days ago
sha256:2827ba9e7632a4b141c50caf1e8f7d77abbc3515be20e7465f2bccb0ac4edf91
fix: repair endpoint now sets has_active_subscription when …
Human
minor
⚠
51 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
83 days ago