refactor(linkedin-studio): M0-9 — REMEMBER.md materializes external (anti-pattern fix)
This commit is contained in:
parent
289eab498e
commit
629ff7ff58
2 changed files with 39 additions and 1 deletions
36
hooks/scripts/__tests__/session-start-remember.test.mjs
Normal file
36
hooks/scripts/__tests__/session-start-remember.test.mjs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { describe, test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { mkdtempSync, rmSync, existsSync } from 'node:fs';
|
||||
import { join, dirname } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
// M0-9: REMEMBER.md must materialize under the EXTERNAL data root (getDataRoot()),
|
||||
// not inside the plugin tree (the old anti-pattern wrote join(PLUGIN_ROOT,
|
||||
// 'REMEMBER.md')). session-start is a procedural hook with no exports, so we run
|
||||
// it as a subprocess with an isolated HOME + LINKEDIN_STUDIO_DATA and check where
|
||||
// REMEMBER.md lands. Pattern: user-prompt-context.test.mjs subprocess harness.
|
||||
const hookPath = join(dirname(fileURLToPath(import.meta.url)), '..', 'session-start.mjs');
|
||||
|
||||
describe('session-start — REMEMBER.md materializes external (M0-9)', () => {
|
||||
test('REMEMBER.md is created under the external data root, not the plugin tree', () => {
|
||||
const home = mkdtempSync(join(tmpdir(), 'lis-ss-home-'));
|
||||
const dataDir = mkdtempSync(join(tmpdir(), 'lis-ss-data-'));
|
||||
try {
|
||||
execFileSync('node', [hookPath], {
|
||||
input: '',
|
||||
env: { ...process.env, HOME: home, USERPROFILE: home, LINKEDIN_STUDIO_DATA: dataDir },
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
|
||||
assert.ok(
|
||||
existsSync(join(dataDir, 'REMEMBER.md')),
|
||||
'REMEMBER.md must be created under the external data root',
|
||||
);
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true });
|
||||
rmSync(dataDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url';
|
|||
import { calculateScore } from './personalization-score.mjs';
|
||||
import { queueToday, queueOverdue, queueUpcoming } from './queue-manager.mjs';
|
||||
import { applyWeekRollover } from './week-rollover.mjs';
|
||||
import { getDataRoot } from './data-root.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
|
|
@ -405,10 +406,11 @@ if (existsSync(STATE_FILE)) {
|
|||
}
|
||||
|
||||
// Read REMEMBER.md for user session context
|
||||
const rememberFile = join(PLUGIN_ROOT, 'REMEMBER.md');
|
||||
const rememberFile = join(getDataRoot(), 'REMEMBER.md');
|
||||
const rememberTemplate = join(PLUGIN_ROOT, 'config', 'REMEMBER.template.md');
|
||||
|
||||
if (!existsSync(rememberFile) && existsSync(rememberTemplate)) {
|
||||
mkdirSync(dirname(rememberFile), { recursive: true });
|
||||
copyFileSync(rememberTemplate, rememberFile);
|
||||
let rememberContent = readFileSync(rememberFile, 'utf-8');
|
||||
const today = new Date().toISOString().slice(0, 10);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue