371900bae5
Memind CI / Test, build, and release guards (pull_request) Failing after 18s
Centralize page HTML quota checks with grace-write semantics across page services and workspace tools, keep localhost MindSpace links clickable in chat display, and expand Page Data/static-page skill plus local dev docs for quota, delivery URLs, and native Aider/OpenHands tooling. Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.8 KiB
JavaScript
50 lines
1.8 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
assertPageWriteQuota,
|
|
evaluatePageWriteQuota,
|
|
isMindSpacePageWriteRelativePath,
|
|
} from './mindspace-space-quota.mjs';
|
|
|
|
const baseSpace = {
|
|
quota_bytes: 100,
|
|
used_bytes: 80,
|
|
reserved_bytes: 0,
|
|
};
|
|
|
|
test('evaluatePageWriteQuota allows normal writes within headroom', () => {
|
|
assert.deepEqual(evaluatePageWriteQuota(baseSpace, 15).reason, 'sufficient');
|
|
});
|
|
|
|
test('evaluatePageWriteQuota allows grace write when headroom is insufficient but not over quota', () => {
|
|
const result = evaluatePageWriteQuota(baseSpace, 30);
|
|
assert.equal(result.reason, 'grace_write');
|
|
assert.equal(result.allowed, true);
|
|
assert.equal(result.grace, true);
|
|
});
|
|
|
|
test('evaluatePageWriteQuota blocks next write after quota is exhausted', () => {
|
|
const over = { quota_bytes: 100, used_bytes: 100, reserved_bytes: 0 };
|
|
const result = evaluatePageWriteQuota(over, 1);
|
|
assert.equal(result.reason, 'over_quota');
|
|
assert.equal(result.allowed, false);
|
|
});
|
|
|
|
test('assertPageWriteQuota throws over-quota message for subsequent writes', () => {
|
|
const over = { quota_bytes: 100, used_bytes: 101, reserved_bytes: 0 };
|
|
assert.throws(
|
|
() => assertPageWriteQuota(over, 1),
|
|
(error) =>
|
|
error.code === 'quota_exceeded' &&
|
|
error.message.includes('空间已满') &&
|
|
error.details?.overQuota === true,
|
|
);
|
|
});
|
|
|
|
test('isMindSpacePageWriteRelativePath matches public and draft html only', () => {
|
|
assert.equal(isMindSpacePageWriteRelativePath('public/bug-tracker.html'), true);
|
|
assert.equal(isMindSpacePageWriteRelativePath('draft/report.html'), true);
|
|
assert.equal(isMindSpacePageWriteRelativePath('private/notes.html'), false);
|
|
assert.equal(isMindSpacePageWriteRelativePath('public/data.json'), false);
|
|
});
|