Skip to content

Commit 34f3cb3

Browse files
committed
feat(WebServer): remove reinject function
1 parent cc69c0d commit 34f3cb3

4 files changed

Lines changed: 10 additions & 255 deletions

File tree

Tools/WebServer/static/js/core/slots.js

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -110,74 +110,6 @@ async function fpbUnpatch(slotId) {
110110
}
111111
}
112112

113-
async function fpbReinject(slotId) {
114-
const state = window.FPBState;
115-
if (!state.isConnected) {
116-
writeToOutput('[ERROR] Not connected', 'error');
117-
return;
118-
}
119-
120-
const slotState = state.slotStates[slotId];
121-
const targetFunc = slotState?.func;
122-
123-
if (!targetFunc) {
124-
writeToOutput(
125-
`[ERROR] Slot ${slotId} is empty, nothing to re-inject`,
126-
'error',
127-
);
128-
return;
129-
}
130-
131-
writeToOutput(
132-
`[INFO] Re-injecting ${targetFunc} to Slot ${slotId}...`,
133-
'info',
134-
);
135-
136-
try {
137-
const sourceRes = await fetch('/api/patch/source');
138-
const sourceData = await sourceRes.json();
139-
140-
if (!sourceData.success || !sourceData.content?.trim()) {
141-
writeToOutput(
142-
'[ERROR] No patch source available. Please use Auto Inject on Save first.',
143-
'error',
144-
);
145-
return;
146-
}
147-
148-
const patchSource = sourceData.content;
149-
const patchMode =
150-
document.getElementById('patchMode')?.value || 'trampoline';
151-
152-
const res = await fetch('/api/fpb/inject', {
153-
method: 'POST',
154-
headers: { 'Content-Type': 'application/json' },
155-
body: JSON.stringify({
156-
source_content: patchSource,
157-
target_func: targetFunc,
158-
patch_mode: patchMode,
159-
comp: slotId,
160-
}),
161-
});
162-
const data = await res.json();
163-
164-
if (data.success) {
165-
writeToOutput(
166-
`[SUCCESS] Re-injected ${targetFunc} to Slot ${slotId}`,
167-
'success',
168-
);
169-
await fpbInfo();
170-
} else {
171-
writeToOutput(
172-
`[ERROR] Re-inject failed: ${data.error || 'Unknown error'}`,
173-
'error',
174-
);
175-
}
176-
} catch (e) {
177-
writeToOutput(`[ERROR] Re-inject error: ${e}`, 'error');
178-
}
179-
}
180-
181113
async function fpbUnpatchAll() {
182114
const state = window.FPBState;
183115
if (!state.isConnected) {
@@ -241,6 +173,5 @@ window.selectSlot = selectSlot;
241173
window.onSlotSelectChange = onSlotSelectChange;
242174
window.initSlotSelectListener = initSlotSelectListener;
243175
window.fpbUnpatch = fpbUnpatch;
244-
window.fpbReinject = fpbReinject;
245176
window.fpbUnpatchAll = fpbUnpatchAll;
246177
window.updateMemoryInfo = updateMemoryInfo;

Tools/WebServer/templates/partials/sidebar_device.html

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@
4545
<span class="slot-func" id="slot{{ i }}Func">Empty</span>
4646
</div>
4747
<div class="slot-actions">
48-
<button
49-
class="slot-btn"
50-
onclick="event.stopPropagation(); fpbReinject({{ i }});"
51-
title="Re-inject this slot"
52-
>
53-
<i class="codicon codicon-debug-restart"></i>
54-
</button>
5548
<button class="slot-btn" onclick="event.stopPropagation(); fpbUnpatch({{ i }});" title="Clear slot">
5649
<i class="codicon codicon-close"></i>
5750
</button>

Tools/WebServer/tests/js/test_slots.js

Lines changed: 10 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ module.exports = function (w) {
2424
assertTrue(typeof w.selectSlot === 'function'));
2525
it('fpbUnpatch is a function', () =>
2626
assertTrue(typeof w.fpbUnpatch === 'function'));
27-
it('fpbReinject is a function', () =>
28-
assertTrue(typeof w.fpbReinject === 'function'));
2927
it('fpbUnpatchAll is a function', () =>
3028
assertTrue(typeof w.fpbUnpatchAll === 'function'));
3129
it('updateMemoryInfo is a function', () =>
@@ -285,69 +283,23 @@ module.exports = function (w) {
285283
w.FPBState.toolTerminal = null;
286284
w.FPBState.isConnected = false;
287285
});
288-
});
289-
290-
describe('fpbReinject Function', () => {
291-
it('is async function', () => {
292-
assertTrue(w.fpbReinject.constructor.name === 'AsyncFunction');
293-
});
294-
295-
it('returns early if not connected', async () => {
296-
resetMocks();
297-
w.FPBState.isConnected = false;
298-
const mockTerm = new MockTerminal();
299-
w.FPBState.toolTerminal = mockTerm;
300-
await w.fpbReinject(0);
301-
assertTrue(
302-
mockTerm._writes.some(
303-
(wr) => wr.msg && wr.msg.includes('Not connected'),
304-
),
305-
);
306-
w.FPBState.toolTerminal = null;
307-
});
308286

309-
it('returns error if slot is empty', async () => {
287+
it('handles fetch exception', async () => {
310288
resetMocks();
311289
w.FPBState.isConnected = true;
312290
const mockTerm = new MockTerminal();
313291
w.FPBState.toolTerminal = mockTerm;
314-
w.FPBState.slotStates = Array(6)
315-
.fill()
316-
.map(() => ({ occupied: false, func: '' }));
317-
await w.fpbReinject(0);
292+
const origFetch = browserGlobals.fetch;
293+
browserGlobals.fetch = async () => {
294+
throw new Error('Network error');
295+
};
296+
global.fetch = browserGlobals.fetch;
297+
await w.fpbUnpatch(0);
318298
assertTrue(
319-
mockTerm._writes.some((wr) => wr.msg && wr.msg.includes('empty')),
299+
mockTerm._writes.some((wr) => wr.msg && wr.msg.includes('ERROR')),
320300
);
321-
w.FPBState.toolTerminal = null;
322-
w.FPBState.isConnected = false;
323-
});
324-
325-
it('fetches patch source before reinject', async () => {
326-
resetMocks();
327-
w.FPBState.isConnected = true;
328-
w.FPBState.toolTerminal = new MockTerminal();
329-
w.FPBState.slotStates = [
330-
{
331-
occupied: true,
332-
func: 'test_func',
333-
orig_addr: '0x1000',
334-
target_addr: '0x2000',
335-
},
336-
{ occupied: false },
337-
{ occupied: false },
338-
{ occupied: false },
339-
{ occupied: false },
340-
{ occupied: false },
341-
];
342-
setFetchResponse('/api/patch/source', {
343-
success: true,
344-
content: 'void test_func() {}',
345-
});
346-
setFetchResponse('/api/fpb/inject', { success: true });
347-
setFetchResponse('/api/fpb/info', { success: true, slots: [] });
348-
await w.fpbReinject(0);
349-
const calls = getFetchCalls();
350-
assertTrue(calls.some((c) => c.url.includes('/api/patch/source')));
301+
browserGlobals.fetch = origFetch;
302+
global.fetch = origFetch;
351303
w.FPBState.toolTerminal = null;
352304
w.FPBState.isConnected = false;
353305
});
@@ -448,126 +400,6 @@ module.exports = function (w) {
448400
});
449401
});
450402

451-
describe('fpbUnpatch Function - Extended', () => {
452-
it('handles fetch exception', async () => {
453-
resetMocks();
454-
w.FPBState.isConnected = true;
455-
const mockTerm = new MockTerminal();
456-
w.FPBState.toolTerminal = mockTerm;
457-
const origFetch = browserGlobals.fetch;
458-
browserGlobals.fetch = async () => {
459-
throw new Error('Network error');
460-
};
461-
global.fetch = browserGlobals.fetch;
462-
await w.fpbUnpatch(0);
463-
assertTrue(
464-
mockTerm._writes.some((wr) => wr.msg && wr.msg.includes('ERROR')),
465-
);
466-
browserGlobals.fetch = origFetch;
467-
global.fetch = origFetch;
468-
w.FPBState.toolTerminal = null;
469-
w.FPBState.isConnected = false;
470-
});
471-
});
472-
473-
describe('fpbReinject Function - Extended', () => {
474-
it('handles no patch source available', async () => {
475-
resetMocks();
476-
w.FPBState.isConnected = true;
477-
const mockTerm = new MockTerminal();
478-
w.FPBState.toolTerminal = mockTerm;
479-
w.FPBState.slotStates = [
480-
{
481-
occupied: true,
482-
func: 'test_func',
483-
orig_addr: '0x1000',
484-
target_addr: '0x2000',
485-
},
486-
{ occupied: false },
487-
{ occupied: false },
488-
{ occupied: false },
489-
{ occupied: false },
490-
{ occupied: false },
491-
];
492-
setFetchResponse('/api/patch/source', { success: false });
493-
await w.fpbReinject(0);
494-
assertTrue(
495-
mockTerm._writes.some(
496-
(wr) => wr.msg && wr.msg.includes('No patch source'),
497-
),
498-
);
499-
w.FPBState.toolTerminal = null;
500-
w.FPBState.isConnected = false;
501-
});
502-
503-
it('handles reinject failure', async () => {
504-
resetMocks();
505-
w.FPBState.isConnected = true;
506-
const mockTerm = new MockTerminal();
507-
w.FPBState.toolTerminal = mockTerm;
508-
w.FPBState.slotStates = [
509-
{
510-
occupied: true,
511-
func: 'test_func',
512-
orig_addr: '0x1000',
513-
target_addr: '0x2000',
514-
},
515-
{ occupied: false },
516-
{ occupied: false },
517-
{ occupied: false },
518-
{ occupied: false },
519-
{ occupied: false },
520-
];
521-
setFetchResponse('/api/patch/source', {
522-
success: true,
523-
content: 'void test() {}',
524-
});
525-
setFetchResponse('/api/fpb/inject', {
526-
success: false,
527-
error: 'Injection failed',
528-
});
529-
await w.fpbReinject(0);
530-
assertTrue(
531-
mockTerm._writes.some((wr) => wr.msg && wr.msg.includes('ERROR')),
532-
);
533-
w.FPBState.toolTerminal = null;
534-
w.FPBState.isConnected = false;
535-
});
536-
537-
it('handles fetch exception', async () => {
538-
resetMocks();
539-
w.FPBState.isConnected = true;
540-
const mockTerm = new MockTerminal();
541-
w.FPBState.toolTerminal = mockTerm;
542-
w.FPBState.slotStates = [
543-
{
544-
occupied: true,
545-
func: 'test_func',
546-
orig_addr: '0x1000',
547-
target_addr: '0x2000',
548-
},
549-
{ occupied: false },
550-
{ occupied: false },
551-
{ occupied: false },
552-
{ occupied: false },
553-
{ occupied: false },
554-
];
555-
const origFetch = browserGlobals.fetch;
556-
browserGlobals.fetch = async () => {
557-
throw new Error('Network error');
558-
};
559-
global.fetch = browserGlobals.fetch;
560-
await w.fpbReinject(0);
561-
assertTrue(
562-
mockTerm._writes.some((wr) => wr.msg && wr.msg.includes('ERROR')),
563-
);
564-
browserGlobals.fetch = origFetch;
565-
global.fetch = origFetch;
566-
w.FPBState.toolTerminal = null;
567-
w.FPBState.isConnected = false;
568-
});
569-
});
570-
571403
describe('selectSlot Function - Extended', () => {
572404
it('opens disassembly for occupied slot', () => {
573405
resetMocks();

Tools/WebServer/tests/test_templates.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ def test_sidebar_device_slots(self):
143143
self.assertIn(f'id="slot{i}Func"', html)
144144

145145
# Check slot actions
146-
self.assertIn("fpbReinject", html)
147146
self.assertIn("fpbUnpatch", html)
148147

149148
def test_editor_partial(self):

0 commit comments

Comments
 (0)