-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanic_attacker_event_chain_test.js
More file actions
167 lines (150 loc) · 4.38 KB
/
Copy pathpanic_attacker_event_chain_test.js
File metadata and controls
167 lines (150 loc) · 4.38 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// SPDX-License-Identifier: MPL-2.0
/**
* panic-attacker PanLL import tests
*
* Verifies that PanLL can parse panic-attacker event-chain exports.
*/
import { assertEquals } from "jsr:@std/assert";
import { parse } from "../src/core/EventChain.res.js";
Deno.test("EventChain.parse - accepts panic-attacker panll export payload", () => {
const payload = JSON.stringify({
format: "panll.event-chain.v0",
generated_at: "2026-02-11T00:00:00Z",
source: {
tool: "panic-attack",
report_path: "reports/panic-attack-report.json"
},
summary: {
program: "/tmp/demo-target",
weak_points: 4,
critical_weak_points: 1,
total_crashes: 2,
robustness_score: 61.5
},
timeline: {
duration_ms: 60000,
events: 2
},
event_chain: [
{
id: "cpu-1",
axis: "cpu",
start_ms: 0,
duration_ms: 15000,
intensity: "Heavy",
status: "ran",
peak_memory: null,
notes: null
},
{
id: "memory-1",
axis: "memory",
start_ms: 15000,
duration_ms: 25000,
intensity: "Medium",
status: "ran",
peak_memory: 536870912,
notes: "memory pressure spike"
}
],
constraints: []
});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
assertEquals(result._0.events.length, 2);
assertEquals(result._0.summary.program, "/tmp/demo-target");
assertEquals(result._0.summary.criticalWeakPoints, 1);
assertEquals(result._0.timeline.events, 2);
assertEquals(result._0.timeline.durationMs, 60000);
assertEquals(result._0.events[1].axis, "memory");
assertEquals(result._0.events[1].peakMemory, 536870912);
});
Deno.test("EventChain.parse - returns error for malformed JSON", () => {
const result = parse("{ this is not valid json");
assertEquals(result.TAG, "Error");
assertEquals(result._0, "Invalid JSON");
});
Deno.test("EventChain.parse - tolerates missing summary with event chain", () => {
const payload = JSON.stringify({
event_chain: [
{
id: "attack-cpu-1",
axis: "cpu",
start_ms: null,
duration_ms: 1200,
intensity: "unknown",
status: "failed",
peak_memory: 1024,
notes: "fallback conversion path"
}
]
});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
assertEquals(result._0.summary, undefined);
assertEquals(result._0.timeline, undefined);
assertEquals(result._0.events.length, 1);
assertEquals(result._0.events[0].status, "failed");
});
Deno.test("EventChain.parse - handles empty event_chain array", () => {
const payload = JSON.stringify({
format: "panll.event-chain.v0",
event_chain: []
});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
assertEquals(result._0.events.length, 0);
});
Deno.test("EventChain.parse - defaults missing event fields", () => {
const payload = JSON.stringify({
event_chain: [
{
// Missing id and duration_ms
axis: "cpu",
start_ms: 0,
intensity: "Light",
status: "ran"
}
]
});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
assertEquals(result._0.events.length, 1);
// Missing id should default to empty string or be handled
// Missing duration_ms should default to 0.0 or be handled
});
Deno.test("EventChain.parse - tolerates extra unknown fields", () => {
const payload = JSON.stringify({
format: "panll.event-chain.v0",
event_chain: [],
unknown_field_1: "should be ignored",
unknown_field_2: 12345,
nested_unknown: { foo: "bar" }
});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
});
Deno.test("EventChain.parse - handles completely empty object", () => {
const payload = JSON.stringify({});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
assertEquals(result._0.events.length, 0);
});
Deno.test("EventChain.parse - handles numeric id coercion", () => {
const payload = JSON.stringify({
event_chain: [
{
id: 12345, // Numeric instead of string
axis: "cpu",
start_ms: 0,
duration_ms: 1000,
intensity: "Light",
status: "ran"
}
]
});
const result = parse(payload);
assertEquals(result.TAG, "Ok");
assertEquals(result._0.events.length, 1);
// Should handle numeric id (either convert to string or accept as-is)
});