Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
Publish MCP to npm / Build, test, and publish MCP (push) Waiting to run
Publish SDK to npm / Build, test, and publish SDK (push) Waiting to run
Sync action catalog to docs / sync (push) Waiting to run
Publish UI to npm / Build and publish UI (push) Waiting to run
Build and Release / preflight (push) Waiting to run
37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { createStreamStorage } from '../src/stream-storage';
|
|
|
|
describe('SNOWLUMA_STREAM_DIR', () => {
|
|
const created: string[] = [];
|
|
|
|
afterEach(() => {
|
|
for (const directory of created.splice(0)) {
|
|
fs.rmSync(directory, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it('uses the system temp directory by default', () => {
|
|
const storage = createStreamStorage({});
|
|
expect(storage.root.endsWith(`${path.sep}onebot-stream`)).toBe(true);
|
|
created.push(storage.root);
|
|
});
|
|
|
|
it('uses a caller directory when the variable is set', () => {
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'snowluma-stream-env-'));
|
|
created.push(root);
|
|
const storage = createStreamStorage({ SNOWLUMA_STREAM_DIR: root });
|
|
expect(storage.root).toBe(fs.realpathSync(root));
|
|
});
|
|
|
|
it('falls back when the variable does not name a usable directory', () => {
|
|
const file = path.join(os.tmpdir(), `snowluma-stream-not-dir-${process.pid}`);
|
|
fs.writeFileSync(file, 'x');
|
|
created.push(file);
|
|
const storage = createStreamStorage({ SNOWLUMA_STREAM_DIR: file });
|
|
expect(storage.root.endsWith(`${path.sep}onebot-stream`)).toBe(true);
|
|
});
|
|
});
|