Skip to content

Commit e23b529

Browse files
committed
Fix Label_44_POS false-positive decode and improve options test
- Move setDecodeLevel() inside the regex match block in Label_44_POS so failed parses are not incorrectly marked as successful. Add failUnknown() fallback for non-matching messages. - Replace indirect console.log spy test with a probe plugin that verifies options are passed directly to the plugin's decode method. https://claude.ai/code/session_01WHPebkdmNV4aEh8wzpzoj5
1 parent 1702ce1 commit e23b529

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

lib/MessageDecoder.labelindex.test.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,34 @@ describe('MessageDecoder label index', () => {
130130
});
131131
});
132132

133+
/**
134+
* A probe plugin that records the options it receives.
135+
*/
136+
class ProbePlugin extends DecoderPlugin {
137+
name = 'probe';
138+
receivedOptions: Options | undefined;
139+
140+
qualifiers() {
141+
return { labels: ['ZP'] };
142+
}
143+
144+
decode(message: Message, options: Options = {}): DecodeResult {
145+
this.receivedOptions = options;
146+
const result = this.initResult(message, 'Probe');
147+
this.setDecodeLevel(result, true, 'full');
148+
return result;
149+
}
150+
}
151+
133152
describe('MessageDecoder options pass-through', () => {
134153
test('passes options to plugins', () => {
135154
const decoder = new MessageDecoder();
136-
const spy = jest.spyOn(console, 'log').mockImplementation();
137-
138-
// Decoding with debug: true should produce debug output from plugins
139-
decoder.decode(
140-
{
141-
label: '44',
142-
text: 'ON01,N33522W084181,KCLT,KPDK,1106,004023,---.-,',
143-
},
144-
{ debug: true },
145-
);
155+
const probe = new ProbePlugin(decoder);
156+
decoder.registerPlugin(probe);
157+
158+
const opts: Options = { debug: true };
159+
decoder.decode({ label: 'ZP', text: 'test' }, opts);
146160

147-
// Should have logged something (the "Usable plugins" log from MessageDecoder
148-
// and potentially plugin debug output)
149-
expect(spy).toHaveBeenCalled();
150-
spy.mockRestore();
161+
expect(probe.receivedOptions).toBe(opts);
151162
});
152163
});

lib/plugins/Label_44_POS.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ export class Label_44_POS extends DecoderPlugin {
7070
);
7171
ResultFormatter.arrivalAirport(decodeResult, results.groups.arrival_icao);
7272
ResultFormatter.altitude(decodeResult, flight_level * 100);
73+
74+
this.setDecodeLevel(decodeResult, true, 'full');
75+
return decodeResult;
7376
}
7477

75-
this.setDecodeLevel(decodeResult, true, 'full');
76-
return decodeResult;
78+
return this.failUnknown(decodeResult, message.text, options);
7779
}
7880
}

0 commit comments

Comments
 (0)