forked from EvoMap/evolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidationReport.test.js
More file actions
148 lines (131 loc) · 4.8 KB
/
Copy pathvalidationReport.test.js
File metadata and controls
148 lines (131 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const { describe, it } = require('node:test');
const assert = require('node:assert/strict');
const { buildValidationReport, isValidValidationReport } = require('../src/gep/validationReport');
describe('buildValidationReport', function () {
it('builds a valid report with minimal input', function () {
const report = buildValidationReport({
geneId: 'gene_test',
commands: ['echo hello'],
results: [{ ok: true, stdout: 'hello', stderr: '' }],
});
assert.equal(report.type, 'ValidationReport');
assert.equal(report.gene_id, 'gene_test');
assert.equal(report.overall_ok, true);
assert.equal(report.commands.length, 1);
assert.equal(report.commands[0].command, 'echo hello');
assert.equal(report.commands[0].ok, true);
assert.ok(report.id.startsWith('vr_'));
assert.ok(report.created_at);
assert.ok(report.asset_id);
assert.ok(report.env_fingerprint);
assert.ok(report.env_fingerprint_key);
});
it('marks overall_ok false when any result fails', function () {
const report = buildValidationReport({
geneId: 'gene_fail',
commands: ['cmd1', 'cmd2'],
results: [
{ ok: true, stdout: 'ok' },
{ ok: false, stderr: 'error' },
],
});
assert.equal(report.overall_ok, false);
});
it('marks overall_ok false when results is empty', function () {
const report = buildValidationReport({
geneId: 'gene_empty',
commands: [],
results: [],
});
assert.equal(report.overall_ok, false);
});
it('handles null geneId', function () {
const report = buildValidationReport({
commands: ['test'],
results: [{ ok: true }],
});
assert.equal(report.gene_id, null);
});
it('computes duration_ms from timestamps', function () {
const report = buildValidationReport({
geneId: 'gene_dur',
commands: ['test'],
results: [{ ok: true }],
startedAt: 1000,
finishedAt: 2500,
});
assert.equal(report.duration_ms, 1500);
});
it('duration_ms is null when timestamps missing', function () {
const report = buildValidationReport({
geneId: 'gene_nodur',
commands: ['test'],
results: [{ ok: true }],
});
assert.equal(report.duration_ms, null);
});
it('truncates stdout/stderr to 4000 chars', function () {
const longOutput = 'x'.repeat(5000);
const report = buildValidationReport({
geneId: 'gene_long',
commands: ['test'],
results: [{ ok: true, stdout: longOutput, stderr: longOutput }],
});
assert.equal(report.commands[0].stdout.length, 4000);
assert.equal(report.commands[0].stderr.length, 4000);
});
it('supports both out/stdout and err/stderr field names', function () {
const report = buildValidationReport({
geneId: 'gene_compat',
commands: ['test'],
results: [{ ok: true, out: 'output_via_out', err: 'error_via_err' }],
});
assert.equal(report.commands[0].stdout, 'output_via_out');
assert.equal(report.commands[0].stderr, 'error_via_err');
});
it('infers commands from results when commands not provided', function () {
const report = buildValidationReport({
geneId: 'gene_infer',
results: [{ ok: true, cmd: 'inferred_cmd' }],
});
assert.equal(report.commands[0].command, 'inferred_cmd');
});
it('uses provided envFp instead of capturing', function () {
const customFp = { device_id: 'custom', platform: 'test' };
const report = buildValidationReport({
geneId: 'gene_fp',
commands: ['test'],
results: [{ ok: true }],
envFp: customFp,
});
assert.equal(report.env_fingerprint.device_id, 'custom');
});
});
describe('isValidValidationReport', function () {
it('returns true for a valid report', function () {
const report = buildValidationReport({
geneId: 'gene_valid',
commands: ['test'],
results: [{ ok: true }],
});
assert.equal(isValidValidationReport(report), true);
});
it('returns false for null', function () {
assert.equal(isValidValidationReport(null), false);
});
it('returns false for non-object', function () {
assert.equal(isValidValidationReport('string'), false);
});
it('returns false for wrong type field', function () {
assert.equal(isValidValidationReport({ type: 'Other', id: 'x', commands: [], overall_ok: true }), false);
});
it('returns false for missing id', function () {
assert.equal(isValidValidationReport({ type: 'ValidationReport', commands: [], overall_ok: true }), false);
});
it('returns false for missing commands', function () {
assert.equal(isValidValidationReport({ type: 'ValidationReport', id: 'x', overall_ok: true }), false);
});
it('returns false for missing overall_ok', function () {
assert.equal(isValidValidationReport({ type: 'ValidationReport', id: 'x', commands: [] }), false);
});
});