Merge remote-tracking branch 'origin/master' into refactor/deepseek-auth
This commit is contained in:
commit
467afc4174
111 files changed
+4473
-1156
No files matched your search
@@ -99,7 +99,7 @@ describe('Loader tree mutation reports', () => {
|
||||
describe('Include patch data ownership', () => {
|
||||
it('detaches file entries even with no patches', () => {
|
||||
const data: EntryOptions[] = [{ id: 'x', name: 'example', config: { value: 1 } }]
|
||||
const result = applyEntryPatches(data, undefined, vi.fn())
|
||||
const result = applyEntryPatches(data, undefined, vi.fn()).data
|
||||
result[0]!.disabled = true
|
||||
;(result[0]!.config as { value: number }).value = 2
|
||||
expect(data).toEqual([{ id: 'x', name: 'example', config: { value: 1 } }])
|
||||
@@ -109,7 +109,7 @@ describe('Include patch data ownership', () => {
|
||||
const insert: EntryOptions[] = [{ id: 'g', name: 'group', group: true,
|
||||
config: [{ id: 'x', name: 'example', config: { value: 1 } }] }]
|
||||
const warn = vi.fn()
|
||||
const result = applyEntryPatches([], [{ insert }, { id: 'x', disabled: true }], warn)
|
||||
const result = applyEntryPatches([], [{ insert }, { id: 'x', disabled: true }], warn).data
|
||||
const children = result[0]!.config as Array<{ disabled?: boolean; config: { value: number } }>
|
||||
expect(children[0]!.disabled).toBe(true)
|
||||
children[0]!.config.value = 2
|
||||
|
||||
@@ -10,11 +10,15 @@ describe('Include YAML dialect', () => {
|
||||
expect(stringifyEntryYaml(parsed)).toBe(source)
|
||||
})
|
||||
|
||||
it('reads binary integers as numbers and dates as strings', () => {
|
||||
expect(parseEntryYaml('- 0b101\n- 2001-01-01\n- ~\n')).toEqual([5, '2001-01-01', null])
|
||||
it('reads scalars under the YAML 1.2 core schema', () => {
|
||||
expect(parseEntryYaml('- 0b101\n- 0o17\n- 0x1F\n- yes\n- 2001-01-01\n- ~\n')).toEqual(['0b101', 15, 31, 'yes', '2001-01-01', null])
|
||||
expect(parseEntryYaml('')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('rejects unknown tags', () => {
|
||||
expect(() => parseEntryYaml('- !!binary aGVsbG8=\n- !custom value\n')).toThrow()
|
||||
})
|
||||
|
||||
it('writes repeated references in full', () => {
|
||||
const shared = { value: 1 }
|
||||
expect(stringifyEntryYaml([{ config: shared }, { config: shared }])).toBe('- config:\n value: 1\n- config:\n value: 1\n')
|
||||
@@ -35,5 +39,13 @@ describe('Include YAML dialect', () => {
|
||||
}
|
||||
expect(entryYamlErrorPosition(error)).toEqual({ line: 3, column: 1 })
|
||||
expect(entryYamlErrorPosition(new Error('other'))).toBeUndefined()
|
||||
let alias: unknown
|
||||
try {
|
||||
parseEntryYaml('- id: a\n config: *missing\n')
|
||||
} catch (caught) {
|
||||
alias = caught
|
||||
}
|
||||
expect(entryYamlErrorPosition(alias)).toEqual({ line: 2, column: 11 })
|
||||
expect(() => parseEntryYaml('- id: a\n config: *later\n- id: b\n config: &later {}\n')).toThrow('Alias *later must follow its anchor')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,129 @@
|
||||
/** Loader rc.9 and Include 1.2 entry validation, located config errors and module lookup failures. */
|
||||
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { Context, FiberState } from '@deepseek-ai/cordis'
|
||||
import Loader, { EntryValidationError, Group, ModuleNotFoundError, type EntryOptions } from '@deepseek-ai/cordis-plugin-loader'
|
||||
import Include, { ConfigFileError } from '@deepseek-ai/cordis-plugin-include'
|
||||
import Schema from '@deepseek-ai/schemastery'
|
||||
import { describe, expect, it, onTestFinished } from 'vitest'
|
||||
|
||||
const Typed = Object.assign((_ctx: Context, _config: { value: number }) => {}, {
|
||||
Config: Schema.object({ value: Schema.number().required() }),
|
||||
})
|
||||
|
||||
// `rows.yml` is the file the root Include reads; other files are reachable through nested includes.
|
||||
async function fixture(files: Record<string, string>) {
|
||||
const dir = await mkdtemp(join(tmpdir(), 'dsh-loader-rc9-'))
|
||||
const pathOf = (name: string) => join(dir, name)
|
||||
for (const [name, content] of Object.entries(files)) await writeFile(pathOf(name), content)
|
||||
const ctx = new Context()
|
||||
onTestFinished(async () => {
|
||||
await ctx.fiber.dispose()
|
||||
await rm(dir, { recursive: true, force: true, maxRetries: 3 })
|
||||
})
|
||||
const errors: unknown[] = []
|
||||
const warnings: unknown[] = []
|
||||
ctx.logger.exporter({
|
||||
export: ({ type, args }: { type: string; args: unknown[] }) => {
|
||||
if (type === 'error') errors.push(...args)
|
||||
if (type === 'warn') warnings.push(...args)
|
||||
},
|
||||
})
|
||||
ctx.baseUrl = pathToFileURL(dir).href + '/'
|
||||
await ctx.plugin(Loader)
|
||||
Object.assign(ctx.loader.builtins, { include: Include, group: Group, example: () => {}, typed: Typed })
|
||||
const id = await ctx.loader.create({ name: 'cordis:include', config: { path: './rows.yml' } })
|
||||
await ctx.loader.await()
|
||||
const entry = ctx.loader.resolve(id)
|
||||
return { ctx, path: pathOf('rows.yml'), pathOf, entry, include: entry.subtree as Include | undefined, errors, warnings }
|
||||
}
|
||||
|
||||
describe('Loader 1.0.0-rc.9 entry options', () => {
|
||||
it('rejects invalid options before a tree changes', async () => {
|
||||
const ctx = new Context()
|
||||
onTestFinished(() => ctx.fiber.dispose())
|
||||
await ctx.plugin(Loader)
|
||||
ctx.loader.builtins.example = () => {}
|
||||
// Options read from a file are untyped; set the invalid values past the compiler.
|
||||
const invalid = { name: 'cordis:example' } as EntryOptions
|
||||
Reflect.set(invalid, 'disabled', 'yes')
|
||||
Reflect.set(invalid, 'isolate', { svc: 1 })
|
||||
const error = await ctx.loader.create(invalid).catch((caught: unknown) => caught)
|
||||
expect(error).toBeInstanceOf(EntryValidationError)
|
||||
expect((error as EntryValidationError).issues).toEqual([
|
||||
{ message: 'disabled must be a boolean', path: ['disabled'] },
|
||||
{ message: 'isolate.svc must be true or a string', path: ['isolate', 'svc'] },
|
||||
])
|
||||
expect(ctx.loader.root.data).toEqual([])
|
||||
await expect(ctx.loader.create({ name: 'cordis:example', group: true })).rejects.toThrow('config is required')
|
||||
})
|
||||
|
||||
it('accepts explicit ids containing the separator from a file', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: pkg:row\n name: cordis:example\n' })
|
||||
expect(app.include!.store['pkg:row']!.fiber!.state).toBe(FiberState.ACTIVE)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Include 1.2.0 config files', () => {
|
||||
it('reports invalid entries and config values at their file positions', async () => {
|
||||
const app = await fixture({ 'rows.yml': [
|
||||
'- id: bad',
|
||||
' name: cordis:example',
|
||||
' disabled: 1',
|
||||
'- id: typed',
|
||||
' name: cordis:typed',
|
||||
' config:',
|
||||
' value: text',
|
||||
'',
|
||||
].join('\n') })
|
||||
const messages = app.errors.map(String).join('\n')
|
||||
expect(messages).toContain(`disabled must be a boolean (at disabled, ${app.path}:3:13)`)
|
||||
expect(messages).toContain(`${app.path}:7:12`)
|
||||
expect(app.include!.store['bad']).toBeUndefined()
|
||||
expect(app.include!.store['typed']!.fiber!.state).not.toBe(FiberState.ACTIVE)
|
||||
})
|
||||
|
||||
it('reports an unknown plugin module at its name position', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: missing\n name: ./missing-plugin.js\n' })
|
||||
const error = app.errors.find(error => error instanceof ModuleNotFoundError)
|
||||
expect(error?.specifier).toBe('./missing-plugin.js')
|
||||
expect(error?.message).toContain(`(at name, ${app.path}:2:9)`)
|
||||
})
|
||||
|
||||
it('parses YAML 1.2 core scalars and locates syntax errors', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: typed\n name: cordis:typed\n config:\n value: 0x10\n' })
|
||||
expect(app.include!.store['typed']!.fiber!.effectiveConfig).toEqual({ value: 16 })
|
||||
await writeFile(app.path, '- id: typed\n name: [\n')
|
||||
await app.include!.refresh()
|
||||
const error = app.warnings.find(warning => warning instanceof ConfigFileError)
|
||||
expect(error).toBeInstanceOf(ConfigFileError)
|
||||
expect((error as ConfigFileError).issues[0]!.location).toMatchObject({ filename: app.path, line: 3 })
|
||||
})
|
||||
|
||||
it('rejects a file with a non-mapping entry at its position', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: ok\n name: cordis:example\n- id: g\n name: cordis:group\n group: true\n config:\n - plain\n' })
|
||||
const error = app.errors.find(error => error instanceof ConfigFileError)
|
||||
expect(error?.issues).toEqual([{ message: 'entry must be an object', location: { filename: app.path, line: 7, column: 7 } }])
|
||||
expect(app.entry.fiber!.state).not.toBe(FiberState.ACTIVE)
|
||||
})
|
||||
|
||||
it('locates an unresolved alias as a parse error', async () => {
|
||||
const app = await fixture({ 'rows.yml': '- id: typed\n name: cordis:typed\n config: *missing\n' })
|
||||
const error = app.errors.find(error => error instanceof ConfigFileError)
|
||||
expect(error?.stage).toBe('parse')
|
||||
expect(error?.issues[0]!.location).toEqual({ filename: app.path, line: 3, column: 11 })
|
||||
})
|
||||
|
||||
it.each([
|
||||
['an override', ' patches:\n - id: typed\n config:\n value: text\n', '- id: typed\n name: cordis:typed\n config:\n value: 1\n', 8],
|
||||
['an inserted entry', ' patches:\n - insert:\n - id: typed\n name: cordis:typed\n config:\n value: text\n', '[]\n', 10],
|
||||
])('locates a config value supplied by %s in the parent file', async (_kind, patches, inner, line) => {
|
||||
const app = await fixture({
|
||||
'rows.yml': `- id: inner\n name: cordis:include\n config:\n path: ./inner.yml\n${patches}`,
|
||||
'inner.yml': inner,
|
||||
})
|
||||
expect(app.errors.map(String).join('\n')).toContain(`(at value, ${app.path}:${String(line)}:`)
|
||||
})
|
||||
})
|
||||
@@ -84,15 +84,18 @@ describe('Loader project resolution', () => {
|
||||
await expect(tree.import('./missing.js')).rejects.toThrow()
|
||||
})
|
||||
|
||||
it('retains native import when helper creation is denied', async () => {
|
||||
it('retains native import while helper creation is denied and retries it later', async () => {
|
||||
const { root, baseUrl } = await fixture()
|
||||
const tree = await treeFor(baseUrl)
|
||||
const denied = vi.mocked(fs.mkdir).mockRejectedValueOnce(Object.assign(new Error('read-only project'), { code: 'EACCES' }))
|
||||
const denied = vi.mocked(fs.mkdir).mockRejectedValue(Object.assign(new Error('read-only project'), { code: 'EACCES' }))
|
||||
onTestFinished(() => { denied.mockReset() })
|
||||
expect(await createResolve(baseUrl)).toBeUndefined()
|
||||
expect(await tree.import('node:path')).toMatchObject({ join })
|
||||
await expect(tree.import('fixture-dep')).rejects.toThrow()
|
||||
expect(existsSync(join(root, '.cordis'))).toBe(false)
|
||||
denied.mockReset()
|
||||
expect(await tree.import('fixture-dep')).toMatchObject({ tag: 'bare-dep' })
|
||||
expect(existsSync(join(root, '.cordis', 'resolve.mjs'))).toBe(true)
|
||||
})
|
||||
|
||||
it('retains native import without a file-backed package scope', async () => {
|
||||
|
||||
@@ -437,7 +437,9 @@ export const LINK_MAP: Readonly<Record<string, string>> = {
|
||||
ForgeReviewRequest: 'forge.md',
|
||||
ForgeReviewResult: 'forge.md',
|
||||
ForgeBaseBranches: 'forge.md',
|
||||
ForgeBranches: 'forge.md',
|
||||
ForgeRemoteBranches: 'forge.md',
|
||||
ForgeRemoteDefault: 'forge.md',
|
||||
ForgeWorktreeBases: 'forge.md',
|
||||
ForgeChangeRequestDiff: 'forge.md',
|
||||
ForgeCommit: 'forge.md',
|
||||
ForgeCommitList: 'forge.md',
|
||||
|
||||
@@ -2771,7 +2771,17 @@
|
||||
},
|
||||
{
|
||||
"doc": "docs/subsystems/forge.md",
|
||||
"symbol": "ForgeBranches",
|
||||
"symbol": "ForgeWorktreeBases",
|
||||
"source": "packages/experimental/client-ui-forge/src/types.ts"
|
||||
},
|
||||
{
|
||||
"doc": "docs/subsystems/forge.md",
|
||||
"symbol": "ForgeRemoteDefault",
|
||||
"source": "packages/experimental/client-ui-forge/src/types.ts"
|
||||
},
|
||||
{
|
||||
"doc": "docs/subsystems/forge.md",
|
||||
"symbol": "ForgeRemoteBranches",
|
||||
"source": "packages/experimental/client-ui-forge/src/types.ts"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -219,7 +219,7 @@ export function verifyDefaultProductIsolation(root: string): ProductIsolationRes
|
||||
failures.push(`${display(filename)}: included composition must contain an entry array`)
|
||||
return
|
||||
}
|
||||
const entries = applyEntryPatches(content as EntryOptions[], entry.config.patches as PatchOptions[] | undefined, () => {})
|
||||
const entries = applyEntryPatches(content as EntryOptions[], entry.config.patches as PatchOptions[] | undefined, () => {}).data
|
||||
scanEntries(entries, filename, true, nestedStack)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ export function verifyProductUse(
|
||||
const content: unknown = existsSync(filename) ? loadCordisYaml(readFileSync(filename, 'utf8')) : row.config.initial
|
||||
configs.add(filename)
|
||||
if (!Array.isArray(content)) { failures.push(`${display(filename)}: Include requires an entry array or initial entries`); continue }
|
||||
const entries = applyEntryPatches(content as EntryOptions[], row.config.patches as PatchOptions[] | undefined, () => {})
|
||||
const entries = applyEntryPatches(content as EntryOptions[], row.config.patches as PatchOptions[] | undefined, () => {}).data
|
||||
scanEntries(entries, filename, reach, new Set([...stack, filename]))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user