import { test } from 'node:test' import assert from 'node:assert/strict' import { plan, servedAtRoot } from '../src/plan.mjs' const site = (name, url, extra = {}) => ({ name, repo: `owner/${name}`, pages: { url }, detect: { truncated: false }, verdict: { effort: 'automatic', deploy: { branch: 'main', dir: '/' }, blockers: [] }, ...extra, }) test('a project site under github.io already lives on a sub-path', () => { assert.equal(servedAtRoot(site('x', 'https://owner.github.io/x/')), false) }) test('a user site and a custom domain are root-served', () => { assert.equal(servedAtRoot(site('owner.github.io', 'https://owner.github.io/')), true) assert.equal(servedAtRoot(site('x', 'https://x.example/', { customDomain: 'x.example' })), true) }) test('only the owner’s own .github.io becomes the index', async () => { const scan = { owner: 'Owner', repos: [ site('someone-else.github.io', 'https://owner.github.io/someone-else.github.io/'), site('owner.github.io', 'https://owner.github.io/'), ], } const p = await plan(scan, { domain: 'd.tngl.io', network: false }) assert.equal(p.indexRepo, 'owner.github.io') assert.deepEqual(p.indexCandidates, []) }) test('with no user site, root-served sites are offered as index candidates', async () => { const scan = { owner: 'owner', repos: [ site('blog', 'https://blog.example/', { customDomain: 'blog.example' }), site('proj', 'https://owner.github.io/proj/'), ], } const p = await plan(scan, { domain: 'd.tngl.io', network: false }) assert.equal(p.indexRepo, null) assert.deepEqual(p.indexCandidates, ['blog']) })