137 lines
3.4 KiB
JavaScript
137 lines
3.4 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
auditConversationPackages,
|
|
buildPublicHtmlArtifactId,
|
|
} from './mindspace-conversation-package-audit.mjs';
|
|
|
|
test('auditConversationPackages reports empty packages', () => {
|
|
const result = auditConversationPackages({
|
|
packages: [
|
|
{
|
|
id: 'cp_session-1',
|
|
user_id: 'user-1',
|
|
session_id: 'session-1',
|
|
},
|
|
],
|
|
artifacts: [],
|
|
assets: [],
|
|
});
|
|
|
|
assert.equal(result.ok, false);
|
|
assert.equal(result.issues[0].code, 'package_without_artifacts');
|
|
});
|
|
|
|
test('auditConversationPackages plans public_html repair for generated public HTML assets', () => {
|
|
const asset = {
|
|
id: 'asset-1',
|
|
workspace_relative_path: 'public/report.html',
|
|
size_bytes: 42,
|
|
updated_at: 1234,
|
|
};
|
|
const result = auditConversationPackages({
|
|
publicBaseUrl: 'https://example.com',
|
|
packages: [
|
|
{
|
|
id: 'cp_session-1',
|
|
user_id: 'user-1',
|
|
session_id: 'session-1',
|
|
},
|
|
],
|
|
artifacts: [
|
|
{
|
|
id: 'ca_workspace_asset-1',
|
|
package_id: 'cp_session-1',
|
|
asset_id: 'asset-1',
|
|
artifact_kind: 'generated_file',
|
|
storage_key:
|
|
'workspace://user-1/public/report.html',
|
|
display_name: 'report.html',
|
|
size_bytes: 42,
|
|
created_at: 1000,
|
|
},
|
|
],
|
|
assets: [asset],
|
|
});
|
|
|
|
assert.equal(result.ok, false);
|
|
assert.equal(result.repairs.length, 1);
|
|
assert.equal(
|
|
result.repairs[0].artifactId,
|
|
buildPublicHtmlArtifactId({
|
|
userId: 'user-1',
|
|
sessionId: 'session-1',
|
|
relativePath: 'public/report.html',
|
|
}),
|
|
);
|
|
assert.equal(
|
|
result.repairs[0].canonicalUrl,
|
|
'https://example.com/MindSpace/user-1/public/report.html',
|
|
);
|
|
});
|
|
|
|
test('auditConversationPackages accepts paired generated_file and public_html artifacts', () => {
|
|
const result = auditConversationPackages({
|
|
packages: [
|
|
{
|
|
id: 'cp_session-1',
|
|
user_id: 'user-1',
|
|
session_id: 'session-1',
|
|
},
|
|
],
|
|
artifacts: [
|
|
{
|
|
id: 'ca_workspace_asset-1',
|
|
package_id: 'cp_session-1',
|
|
asset_id: 'asset-1',
|
|
artifact_kind: 'generated_file',
|
|
storage_key:
|
|
'workspace://user-1/public/report.html',
|
|
display_name: 'report.html',
|
|
},
|
|
{
|
|
id: 'ca_public_html_report',
|
|
package_id: 'cp_session-1',
|
|
artifact_kind: 'public_html',
|
|
display_name: 'report.html',
|
|
canonical_url:
|
|
'https://example.com/MindSpace/user-1/public/report.html',
|
|
},
|
|
],
|
|
assets: [
|
|
{
|
|
id: 'asset-1',
|
|
workspace_relative_path: 'public/report.html',
|
|
},
|
|
],
|
|
});
|
|
|
|
assert.equal(result.ok, true);
|
|
assert.equal(result.repairs.length, 0);
|
|
});
|
|
|
|
test('auditConversationPackages reports artifacts pointing at missing assets', () => {
|
|
const result = auditConversationPackages({
|
|
packages: [
|
|
{
|
|
id: 'cp_session-1',
|
|
user_id: 'user-1',
|
|
session_id: 'session-1',
|
|
},
|
|
],
|
|
artifacts: [
|
|
{
|
|
id: 'ca_missing_asset',
|
|
package_id: 'cp_session-1',
|
|
asset_id: 'asset-missing',
|
|
artifact_kind: 'generated_file',
|
|
canonical_url: '/api/mindspace/v1/assets/asset-missing/download',
|
|
},
|
|
],
|
|
assets: [],
|
|
});
|
|
|
|
assert.equal(result.ok, false);
|
|
assert.equal(result.issues[0].code, 'artifact_asset_missing');
|
|
});
|