hub-setup.test.mjs
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2
feat(auth): persistent login system + C7 session introspection
Human
minor
⚠ breaking
16 days ago
| 1 | /** |
| 2 | * Hub setup read/write tests. |
| 3 | */ |
| 4 | import { describe, it, after } from 'node:test'; |
| 5 | import assert from 'node:assert'; |
| 6 | import fs from 'fs'; |
| 7 | import path from 'path'; |
| 8 | import { fileURLToPath } from 'url'; |
| 9 | import { readHubSetup, writeHubSetup } from '../lib/hub-setup.mjs'; |
| 10 | |
| 11 | const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 12 | // Own directory so parallel runs do not race config.test.mjs on test/fixtures/data/hub_setup.yaml. |
| 13 | const dataDir = path.join(__dirname, 'fixtures', 'hub-setup-test-data'); |
| 14 | const hubSetupPath = path.join(dataDir, 'hub_setup.yaml'); |
| 15 | |
| 16 | function cleanup() { |
| 17 | try { fs.unlinkSync(hubSetupPath); } catch (_) {} |
| 18 | try { fs.rmdirSync(dataDir); } catch (_) {} |
| 19 | } |
| 20 | |
| 21 | describe('hub-setup', () => { |
| 22 | after(cleanup); |
| 23 | |
| 24 | it('readHubSetup returns null when file does not exist', () => { |
| 25 | cleanup(); |
| 26 | assert.strictEqual(readHubSetup(dataDir), null); |
| 27 | }); |
| 28 | |
| 29 | it('writeHubSetup creates file and readHubSetup reads it', () => { |
| 30 | cleanup(); |
| 31 | writeHubSetup(dataDir, { |
| 32 | vault: { git: { enabled: true, remote: 'https://github.com/u/r.git' } }, |
| 33 | }); |
| 34 | const read = readHubSetup(dataDir); |
| 35 | assert(read !== null); |
| 36 | assert.strictEqual(read.vault?.git?.enabled, true); |
| 37 | assert.strictEqual(read.vault?.git?.remote, 'https://github.com/u/r.git'); |
| 38 | }); |
| 39 | |
| 40 | it('writeHubSetup rejects empty vault_path', () => { |
| 41 | assert.throws( |
| 42 | () => writeHubSetup(dataDir, { vault_path: ' ' }), |
| 43 | /vault_path cannot be empty/ |
| 44 | ); |
| 45 | }); |
| 46 | |
| 47 | it('writeHubSetup merges with existing vault.git', () => { |
| 48 | cleanup(); |
| 49 | writeHubSetup(dataDir, { vault_path: './vault', vault: { git: { enabled: true, remote: 'https://a.git' } } }); |
| 50 | writeHubSetup(dataDir, { vault: { git: { remote: 'https://b.git' } } }); |
| 51 | const read = readHubSetup(dataDir); |
| 52 | assert.strictEqual(read?.vault_path, './vault'); |
| 53 | assert.strictEqual(read?.vault?.git?.enabled, true); |
| 54 | assert.strictEqual(read?.vault?.git?.remote, 'https://b.git'); |
| 55 | }); |
| 56 | }); |
File History
2 commits
sha256:8d46372e39d2d5a54fd93a8b1c27922fe0d9b22a72197345f1d2c71701cc4ce2
feat(auth): persistent login system + C7 session introspection
Human
minor
⚠
16 days ago
sha256:6a102aafafdfe7e70a24f4e59740200f0ee713ce7915f1b53e9d4ba5ee8b4410
Initial Muse snapshot
Human
48 days ago