test: close the per-file coverage gaps this PR opened
The layered-env reader gained an unreadable-layer path, a default reporter, and two absent-layer arms with no cases; the credential store gained two error paths that must not be mistaken for an absent file. The platform arms and the `linePos` guard cannot be reached from a POSIX test run — the first is covered by the native Windows job, the second only satisfies an optional type that `prettyErrors` always fills — so both carry a v8 ignore naming why.
This commit is contained in:
@@ -101,6 +101,7 @@ const GROUP_OTHER_BITS = 0o077
|
||||
* @throws when the file exists with group or other permission bits set.
|
||||
*/
|
||||
async function assertOwnerOnly(filename: string): Promise<void> {
|
||||
/* v8 ignore next -- native Windows coverage exercises the skip; POSIX covers the check */
|
||||
if (process.platform === 'win32') return
|
||||
let mode: number
|
||||
try {
|
||||
@@ -130,6 +131,7 @@ function isENOENT(error: unknown): boolean {
|
||||
*/
|
||||
function describeYamlError(error: YAMLError): string {
|
||||
const at = error.linePos?.[0]
|
||||
/* v8 ignore next -- `prettyErrors` populates linePos on every error; the guard answers its optional type */
|
||||
const where = at === undefined ? '' : ` at line ${String(at.line)}, column ${String(at.col)}`
|
||||
return `${error.code}${where}`
|
||||
}
|
||||
|
||||
@@ -179,6 +179,29 @@ describe('layer ladder', () => {
|
||||
.rejects.toThrow(/readable beyond its owner \(mode 644\)/)
|
||||
})
|
||||
|
||||
it('propagates a permission check that fails for a reason other than absence', async () => {
|
||||
const dir = await tempDir()
|
||||
const notADirectory = join(dir, 'occupied')
|
||||
await writeFile(notADirectory, 'a regular file\n')
|
||||
// An absent document is an empty store, but a path that cannot be
|
||||
// reached at all is a misconfiguration: the parent is a file, so the
|
||||
// check fails with ENOTDIR rather than concluding "no credentials yet".
|
||||
const ctx = new Context()
|
||||
await expect(ctx.plugin(CredentialsLocal, { path: join(notADirectory, '.credentials.yaml'), watch: false }))
|
||||
.rejects.toThrow(/ENOTDIR/)
|
||||
})
|
||||
|
||||
it('propagates a read that fails for a reason other than absence', async () => {
|
||||
const dir = await tempDir()
|
||||
const path = join(dir, '.credentials.yaml')
|
||||
// Owner-only, so the permission check passes, and unreadable as a file:
|
||||
// the store is present but cannot be parsed, which must fail the launch
|
||||
// rather than silently serve nothing.
|
||||
await mkdir(path, { mode: 0o700 })
|
||||
const ctx = new Context()
|
||||
await expect(ctx.plugin(CredentialsLocal, { path, watch: false })).rejects.toThrow(/EISDIR/)
|
||||
})
|
||||
|
||||
it('lets only the inherited environment shadow the store, read-only', async () => {
|
||||
const dir = await tempDir()
|
||||
const path = join(dir, '.credentials.yaml')
|
||||
|
||||
Reference in New Issue
Block a user