@cortexkit/common-auth 0.39.0 → 0.39.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
type LeaseCreationTestHooks = {
|
|
2
|
+
beforeWrite?: (path: string) => void | Promise<void>;
|
|
3
|
+
beforeLink?: (tempPath: string, lockPath: string) => void | Promise<void>;
|
|
4
|
+
};
|
|
5
|
+
/** Test-only creation faults; not re-exported from the public fs entry point. */
|
|
6
|
+
export declare function setLeaseCreationTestHooksForTest(hooks?: LeaseCreationTestHooks): void;
|
|
1
7
|
export declare function isLostMarkerRaceError(error: unknown): boolean;
|
|
2
8
|
/** Test-only fault injection between marker mkdir and owner.json write. */
|
|
3
9
|
export interface EvictionMarkerTestHooks {
|
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { lstat, mkdir, open, readFile, rename, rm, stat, } from 'node:fs/promises';
|
|
2
|
+
import { link, lstat, mkdir, open, readFile, rename, rm, stat, } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, isWindowsSharingViolation, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from './private-files.js';
|
|
5
5
|
import { LockOwnershipError, lockPathFor } from './with-lock.js';
|
|
6
|
+
let leaseCreationTestHooks;
|
|
7
|
+
/** Test-only creation faults; not re-exported from the public fs entry point. */
|
|
8
|
+
export function setLeaseCreationTestHooksForTest(hooks) {
|
|
9
|
+
leaseCreationTestHooks = hooks;
|
|
10
|
+
}
|
|
11
|
+
async function createExclusiveText(path, text) {
|
|
12
|
+
// Publish only a complete owner record. A crash before link leaves at most
|
|
13
|
+
// an orphaned staging file, never an ownerless lease at the lock path.
|
|
14
|
+
const tempPath = `${path}.${randomUUID()}.tmp`;
|
|
15
|
+
let handle;
|
|
16
|
+
try {
|
|
17
|
+
handle = await open(tempPath, 'wx', 0o600);
|
|
18
|
+
try {
|
|
19
|
+
if (leaseCreationTestHooks?.beforeWrite)
|
|
20
|
+
await leaseCreationTestHooks.beforeWrite(tempPath);
|
|
21
|
+
await handle.writeFile(text, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await handle.close();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
if (leaseCreationTestHooks?.beforeLink)
|
|
28
|
+
await leaseCreationTestHooks.beforeLink(tempPath, path);
|
|
29
|
+
await link(tempPath, path);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const code = error.code;
|
|
33
|
+
if (code !== 'EPERM' &&
|
|
34
|
+
code !== 'ENOTSUP' &&
|
|
35
|
+
code !== 'EOPNOTSUPP' &&
|
|
36
|
+
code !== 'EXDEV')
|
|
37
|
+
throw error;
|
|
38
|
+
// Filesystems without hard links still use exclusive create then write.
|
|
39
|
+
// A crash can leave an incomplete lease there, but locking stays available.
|
|
40
|
+
await writeExclusiveText(path, text);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
if (handle)
|
|
45
|
+
await rm(tempPath, { force: true }).catch(() => { });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
6
48
|
/**
|
|
7
49
|
* Create a new owner-only file and write `text` into it, failing with EEXIST if
|
|
8
50
|
* the file already exists. Writing through the handle rather than path-based
|
|
@@ -11,7 +53,7 @@ import { LockOwnershipError, lockPathFor } from './with-lock.js';
|
|
|
11
53
|
* that redundant ftruncate stalls for hundreds of milliseconds, inside every
|
|
12
54
|
* lock acquisition.
|
|
13
55
|
*/
|
|
14
|
-
async function
|
|
56
|
+
async function writeExclusiveText(path, text) {
|
|
15
57
|
const handle = await open(path, 'wx', 0o600);
|
|
16
58
|
let createdStat;
|
|
17
59
|
try {
|
|
@@ -21,6 +63,8 @@ async function createExclusiveText(path, text) {
|
|
|
21
63
|
createdStat = undefined;
|
|
22
64
|
}
|
|
23
65
|
try {
|
|
66
|
+
if (leaseCreationTestHooks?.beforeWrite)
|
|
67
|
+
await leaseCreationTestHooks.beforeWrite(path);
|
|
24
68
|
await handle.writeFile(text, 'utf8');
|
|
25
69
|
}
|
|
26
70
|
catch (error) {
|
|
@@ -491,7 +535,7 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
491
535
|
if (windowsPrivateFiles)
|
|
492
536
|
await createPrivateBytes(evictOwnerPath, bytes);
|
|
493
537
|
else
|
|
494
|
-
await
|
|
538
|
+
await writeExclusiveText(evictOwnerPath, bytes);
|
|
495
539
|
}
|
|
496
540
|
catch (error) {
|
|
497
541
|
// A competing contender can rename our just-created marker directory
|
|
@@ -38,7 +38,8 @@ export function turnNotes(sessionId) {
|
|
|
38
38
|
if (typeof afterToolUseId !== 'string' ||
|
|
39
39
|
afterToolUseId.length === 0 ||
|
|
40
40
|
typeof text !== 'string' ||
|
|
41
|
-
|
|
41
|
+
// A whitespace-only note says nothing and a provider may refuse it.
|
|
42
|
+
text.trim().length === 0 ||
|
|
42
43
|
encoder.encode(text).byteLength > 16_384)
|
|
43
44
|
continue;
|
|
44
45
|
notes.push({ afterToolUseId, text });
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package records `npm pack --json` printed. Up to npm 11 it prints an
|
|
3
|
+
* array of records; from npm 12 an object keyed by package name. The records
|
|
4
|
+
* themselves (`filename`, `files[].path`) have the same fields in both.
|
|
5
|
+
*/
|
|
6
|
+
export declare function packedRecords<T>(parsed: unknown): T[];
|
|
1
7
|
/** Compare the files npm actually publishes, not the manifest's glob patterns. */
|
|
2
8
|
export declare function assertEmittedPublishList(packageRoot: string, destinationDir: string, emitted: readonly string[]): Promise<void>;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
2
|
import { relative, resolve } from 'node:path';
|
|
3
3
|
import { promisify } from 'node:util';
|
|
4
|
+
/**
|
|
5
|
+
* The package records `npm pack --json` printed. Up to npm 11 it prints an
|
|
6
|
+
* array of records; from npm 12 an object keyed by package name. The records
|
|
7
|
+
* themselves (`filename`, `files[].path`) have the same fields in both.
|
|
8
|
+
*/
|
|
9
|
+
export function packedRecords(parsed) {
|
|
10
|
+
if (Array.isArray(parsed))
|
|
11
|
+
return parsed;
|
|
12
|
+
if (parsed !== null && typeof parsed === 'object')
|
|
13
|
+
return Object.values(parsed);
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
4
16
|
/** Compare the files npm actually publishes, not the manifest's glob patterns. */
|
|
5
17
|
export async function assertEmittedPublishList(packageRoot, destinationDir, emitted) {
|
|
6
18
|
const { stdout } = await promisify(execFile)('npm', ['pack', '--json', '--dry-run', '--ignore-scripts'], { cwd: packageRoot });
|
|
7
|
-
const packed = JSON.parse(stdout);
|
|
19
|
+
const packed = packedRecords(JSON.parse(stdout));
|
|
8
20
|
const prefix = `${relative(resolve(packageRoot), resolve(destinationDir)).split('\\').join('/')}/`;
|
|
9
21
|
const packageInfo = packed[0];
|
|
10
22
|
if (!packageInfo)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/common-auth",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.1",
|
|
4
4
|
"description": "Shared code for the CortexKit auth plugins: account pool, quota and routing, commands and auth menu, OpenCode 2 hooks, Claustrum custody, and plumbing (loopback RPC, file locks, logger, sidebar state, TUI preferences and build).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|