pgserve 2.0.0 → 2.0.2

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.
@@ -27,9 +27,7 @@ function silentLogger() {
27
27
  }
28
28
 
29
29
  function makeIsolated(tag) {
30
- const dir = path.join(os.tmpdir(), `pgserve-daemon-fp-${tag}-${process.pid}-${Date.now()}`);
31
- fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
32
- return dir;
30
+ return fs.mkdtempSync(path.join('/tmp', `pgs-fp-${tag}-`));
33
31
  }
34
32
 
35
33
  function readAuditLines(logFile) {
@@ -53,6 +51,10 @@ describe('Group 3 — daemon emits connection_routed on accept', () => {
53
51
  auditLogFile,
54
52
  auditTarget: 'file',
55
53
  logger: silentLogger(),
54
+ _fingerprintAcceptOpts: () => ({
55
+ cwdOverride: dir,
56
+ cmdlineOverride: [process.execPath, import.meta.url],
57
+ }),
56
58
  });
57
59
  await daemon.start();
58
60
 
@@ -16,7 +16,6 @@
16
16
 
17
17
  import { describe, test, expect } from 'bun:test';
18
18
  import fs from 'fs';
19
- import os from 'os';
20
19
  import path from 'path';
21
20
 
22
21
  import { PostgresManager } from '../src/postgres.js';
@@ -36,9 +35,7 @@ function silentLogger() {
36
35
  // Each test uses a unique controlSocketDir under tmp so concurrent runs
37
36
  // (and the existing host's real /run/user/<uid>/pgserve) cannot collide.
38
37
  function makeDaemonDirs(tag) {
39
- const dir = path.join(os.tmpdir(), `pgserve-daemon-test-${tag}-${process.pid}-${Date.now()}`);
40
- fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
41
- return dir;
38
+ return fs.mkdtempSync(path.join('/tmp', `pgs-${tag}-`));
42
39
  }
43
40
 
44
41
  describe('PR #24 regression — PostgresManager lifecycle', () => {
@@ -20,6 +20,8 @@ import {
20
20
  initFingerprintFfi,
21
21
  getPeerCred,
22
22
  findNearestPackageJson,
23
+ parseDarwinLsofCwd,
24
+ readProcCwd,
23
25
  readPackageName,
24
26
  derivePackageFingerprint,
25
27
  deriveScriptFingerprint,
@@ -80,6 +82,18 @@ test('getPeerCred reads kernel-attested pid/uid/gid via Unix socket pair', async
80
82
  expect(cred.gid).toBe(expectedGid);
81
83
  });
82
84
 
85
+ test('macOS lsof parser extracts cwd field output', () => {
86
+ const cwd = path.join(scratch, 'project');
87
+ const output = `p12345\nn${cwd}\n`;
88
+ expect(parseDarwinLsofCwd(output)).toBe(cwd);
89
+ expect(parseDarwinLsofCwd('p12345\n')).toBeNull();
90
+ });
91
+
92
+ test('readProcCwd resolves the current process cwd on supported platforms', () => {
93
+ if (process.platform !== 'linux' && process.platform !== 'darwin') return;
94
+ expect(readProcCwd(process.pid)).toBe(process.cwd());
95
+ });
96
+
83
97
  // ---------------------------------------------------------------------------
84
98
  // Pure-function tests on derivation surface
85
99
  // ---------------------------------------------------------------------------
@@ -0,0 +1,71 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import fs from 'fs';
3
+ import os from 'os';
4
+ import path from 'path';
5
+
6
+ import {
7
+ buildDaemonArgs,
8
+ daemonClientOptions,
9
+ probeDaemon,
10
+ resolveLibpqCompatPath,
11
+ resolvePidLockPath,
12
+ } from '../src/index.js';
13
+
14
+ function makeDir(tag) {
15
+ const dir = path.join(os.tmpdir(), `pgserve-sdk-${tag}-${process.pid}-${Date.now()}`);
16
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
17
+ return dir;
18
+ }
19
+
20
+ describe('SDK daemon helpers', () => {
21
+ test('daemonClientOptions returns libpq socket connection settings', () => {
22
+ expect(daemonClientOptions({ controlSocketDir: '/tmp/pgserve' })).toEqual({
23
+ host: '/tmp/pgserve',
24
+ port: 5432,
25
+ database: 'postgres',
26
+ username: 'postgres',
27
+ password: '',
28
+ });
29
+ });
30
+
31
+ test('buildDaemonArgs exposes persistent, pgvector, and listen options', () => {
32
+ expect(buildDaemonArgs({
33
+ dataDir: '/var/lib/pgserve',
34
+ logLevel: 'warn',
35
+ pgvector: true,
36
+ listens: ['127.0.0.1:15432'],
37
+ })).toEqual([
38
+ 'daemon',
39
+ '--data',
40
+ '/var/lib/pgserve',
41
+ '--log',
42
+ 'warn',
43
+ '--pgvector',
44
+ '--listen',
45
+ '127.0.0.1:15432',
46
+ ]);
47
+ });
48
+
49
+ test('probeDaemon reports missing and stale daemon state', () => {
50
+ const dir = makeDir('probe');
51
+ try {
52
+ expect(probeDaemon({ controlSocketDir: dir })).toMatchObject({
53
+ running: false,
54
+ pid: null,
55
+ reason: 'no daemon',
56
+ });
57
+
58
+ fs.writeFileSync(resolvePidLockPath(dir), '999999', { mode: 0o600 });
59
+ fs.writeFileSync(path.join(dir, 'control.sock'), '');
60
+ fs.symlinkSync('control.sock', resolveLibpqCompatPath(dir));
61
+ expect(probeDaemon({ controlSocketDir: dir })).toMatchObject({
62
+ running: false,
63
+ pid: null,
64
+ libpqSocketPresent: true,
65
+ reason: 'stale pid',
66
+ });
67
+ } finally {
68
+ fs.rmSync(dir, { recursive: true, force: true });
69
+ }
70
+ });
71
+ });