build(release): enforce neutral runtime layout

Keep release files at the archive root and reject product-named directory components before CI packages artifacts.

Use neutral directories for media staging, WebUI uploads, stream storage, and MCP downloads so packaged and runtime layouts remain consistent.
This commit is contained in:
DrSmoothl committed 2026-08-06 23:08:19 +08:00
1 parent c0e73cd738
commit f1ae0736c6
11 files changed
+53 -8

No files matched your search

+3
View File
@@ -143,6 +143,9 @@ jobs:
working-directory: dist
run: npm install --omit=dev
- name: Verify release layout
run: pnpm check:release-layout
# Naming convention:
# SnowLuma-dev-<arch>.zip|tar.gz – zero-install (node bundled)
# SnowLuma-dev-<arch>-lite.zip|tar.gz – user provides Node 22.13+ (23.x requires 23.4+)
+3
View File
@@ -96,6 +96,9 @@ jobs:
working-directory: dist
run: npm install --omit=dev
- name: Verify release layout
run: pnpm check:release-layout
# Naming convention:
# SnowLuma-<tag>-<arch>.zip|tar.gz – zero-install (node bundled)
# SnowLuma-<tag>-<arch>-lite.zip|tar.gz – user provides Node 22.13+ (23.x requires 23.4+)
+1
View File
@@ -11,6 +11,7 @@
"build:webui": "pnpm --filter webui build",
"build:mcp": "pnpm --filter @snowluma/mcp build",
"build:all": "pnpm --filter @snowluma/core build:all && pnpm --filter @snowluma/sdk build && pnpm --filter @snowluma/mcp build && pnpm --filter @snowluma/ui build && pnpm --filter webui build",
"check:release-layout": "node tools/check-release-layout.mjs",
"dev": "pnpm --filter @snowluma/core dev",
"dev:mode": "cd dist && cross-env SNOWLUMA_DEV_MODE=1 SNOWLUMA_DEV_WEBUI=1 node index.mjs",
"dev:web": "pnpm --filter webui dev",
+1 -1
View File
@@ -23,7 +23,7 @@ import { traceWebuiMutationRequestChunk } from './mutation-trace';
/** Temp dir for browser→server uploads. Siblings the Stream API's temp root but
* kept distinct so the two cleanup stories don't entangle. */
export const DEBUG_UPLOAD_DIR = path.join(os.tmpdir(), 'snowluma-debug-upload');
export const DEBUG_UPLOAD_DIR = path.join(os.tmpdir(), 'webui-upload');
/** Hard ceiling on a single upload. Mirrors the Stream API's upload cap. */
export const MAX_UPLOAD_BYTES = 4 * 1024 * 1024 * 1024; // 4 GiB
@@ -51,6 +51,10 @@ describe('safeUploadName', () => {
});
describe('uploadDestPath', () => {
it('uses a neutral temporary directory name', () => {
expect(path.basename(DEBUG_UPLOAD_DIR)).toBe('webui-upload');
});
it('produces a unique path inside the upload dir', () => {
const a = uploadDestPath('pic.png');
const b = uploadDestPath('pic.png');
+2 -2
View File
@@ -56,7 +56,7 @@ reported as MCP errors because they mean no complete stream result was committed
| `SNOWLUMA_MCP_TOKEN` | Access token (sent as `Authorization: Bearer …`), if the endpoint requires one. |
| `SNOWLUMA_MCP_TIMEOUT_MS` | Ordinary-action request timeout; for Stream Actions, connection timeout **and per-read idle timeout** (the idle deadline resets after every body read). Default `30000`. Invalid values fail startup. |
| `SNOWLUMA_MCP_MODE` | `docs` \| `read` \| `write`. Default: `read` when an endpoint is set, else `docs`. Invalid values fail startup. |
| `SNOWLUMA_MCP_STREAM_DIR` | Directory on the MCP host for completed Stream Action downloads. Created and validated at startup. Default: `os.tmpdir()/snowluma-mcp/downloads`. |
| `SNOWLUMA_MCP_STREAM_DIR` | Directory on the MCP host for completed Stream Action downloads. Created and validated at startup. Default: `os.tmpdir()/onebot-mcp-downloads`. |
| `SNOWLUMA_MCP_UPLOAD_ROOT` | Existing directory on the MCP host from which automatic uploads may read. Automatic upload is disabled when absent. |
| `SNOWLUMA_MCP_MAX_STREAM_BYTES` | Per-file download/upload ceiling in bytes. Positive integer up to 4 GiB; default `4294967296`. Invalid values fail server startup. |
@@ -90,7 +90,7 @@ groups, etc.). Enable deliberately:
"SNOWLUMA_MCP_ENDPOINT": "http://127.0.0.1:3000/",
"SNOWLUMA_MCP_TOKEN": "your-access-token",
"SNOWLUMA_MCP_MODE": "write",
"SNOWLUMA_MCP_STREAM_DIR": "/var/tmp/snowluma-mcp-downloads",
"SNOWLUMA_MCP_STREAM_DIR": "/var/tmp/onebot-mcp-downloads",
"SNOWLUMA_MCP_UPLOAD_ROOT": "/home/me/mcp-share"
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ import { createHash, randomUUID } from 'node:crypto';
const DEFAULT_TIMEOUT_MS = 30_000;
const DEFAULT_MAX_STREAM_BYTES = 4 * 1024 * 1024 * 1024;
const DEFAULT_STREAM_DIR = path.join(os.tmpdir(), 'snowluma-mcp', 'downloads');
const DEFAULT_STREAM_DIR = path.join(os.tmpdir(), 'onebot-mcp-downloads');
const MAX_GENERIC_FRAMES = 256;
const MAX_GENERIC_TEXT_BYTES = 256 * 1024;
// OneBot permits a 16 MiB decoded download chunk. Base64 expands that to
+1 -1
View File
@@ -273,7 +273,7 @@ function resolveManagedRoot(input: string): string {
return path.join(fs.realpathSync(parent), path.basename(absolute));
}
export const streamStorage = new StreamStorage(path.join(os.tmpdir(), 'snowluma-stream'));
export const streamStorage = new StreamStorage(path.join(os.tmpdir(), 'onebot-stream'));
export const STREAM_ROOT = streamStorage.root;
export const STREAM_UPLOAD_DIR = streamStorage.uploadDir;
export const STREAM_DOWNLOAD_DIR = streamStorage.downloadDir;
@@ -161,7 +161,7 @@ export async function encodeSilk(inputFile: string, tempDir: string): Promise<En
/** Default location for temporary silk files. */
export function defaultPttTempDir(): string {
return path.join(os.tmpdir(), 'snowluma-ptt');
return path.join(os.tmpdir(), 'audio-upload');
}
// ── audio transcode (get_record out_format, #165) ──
@@ -220,7 +220,7 @@ export async function convertAudioBytes(
}
const addon = deps.addon ?? getFFmpegAddon();
const maxOut = deps.maxOutputBytes ?? DEFAULT_MAX_AUDIO_OUTPUT;
const dir = deps.tmpDir ?? path.join(os.tmpdir(), 'snowluma-rec');
const dir = deps.tmpDir ?? path.join(os.tmpdir(), 'audio-transcode');
fs.mkdirSync(dir, { recursive: true });
const id = crypto.randomBytes(8).toString('hex');
const inPath = path.join(dir, `${id}.in`);
+1 -1
View File
@@ -32,7 +32,7 @@ import {
const log = createLogger('Highway.Stage');
export const STAGE_DIR = path.join(os.tmpdir(), 'snowluma-stage');
export const STAGE_DIR = path.join(os.tmpdir(), 'media-stage');
// Must comfortably exceed the slowest plausible single upload (a 1.5 GiB PUT at
// a few MB/s is ~5-10 min). Only unregistered (crash-orphaned) temps are reaped.
const STAGE_TTL_MS = 30 * 60 * 1000;
+34
View File
@@ -0,0 +1,34 @@
import fs from 'node:fs';
import path from 'node:path';
const root = path.resolve(process.argv[2] ?? 'dist');
const entryPoint = path.join(root, 'index.mjs');
if (!fs.statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
throw new Error(`release directory does not exist: ${root}`);
}
if (!fs.statSync(entryPoint, { throwIfNoEntry: false })?.isFile()) {
throw new Error(`release entry point must be at the archive root: ${entryPoint}`);
}
const forbidden = [];
const pending = [root];
while (pending.length > 0) {
const directory = pending.pop();
if (!directory) continue;
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
const absolute = path.join(directory, entry.name);
if (/snowluma/i.test(entry.name)) {
forbidden.push(path.relative(root, absolute));
}
pending.push(absolute);
}
}
if (forbidden.length > 0) {
throw new Error(`release contains forbidden directory names:\n${forbidden.join('\n')}`);
}
console.log(`Release layout verified: ${root}`);