feat(fls): import installed programs and their settings
importProject carries a host's installed programs into the model with the settings Swift keeps (web server port, Gnutella peer limit, DNS recursion and forwarder, personal firewall) and two it does not (the echo server's port, the generic client's target), plus Java's "switched on". The Swift oracle writes programs and settings; they match on the 13 files Swift reads completely. Intended differences, named in the test: - every FILIUS program is kept; Swift drops command prompt, text editor, file explorer, image viewer, echo server and generic client; - a web server's files stay in /webserver, its document root; Swift moves them to /www. No program state goes into a host's files. - multicast_server.fls: maxTeilnehmerZahl refers to a shared Integer (a button's icon text gap, 4); Swift falls back to 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
importProject,
|
||||
readFlsArchive,
|
||||
readTopology,
|
||||
type FlsApplication,
|
||||
type FlsFileTree,
|
||||
type FlsNode,
|
||||
type FlsTopology,
|
||||
@@ -91,6 +92,9 @@ function fileEntriesOf(fileSystem: VirtualFileSystem | undefined): unknown {
|
||||
const DEFAULT_FILES = describeFileEntries(VirtualFileSystem.defaultForDevice().allEntries());
|
||||
const EMPTY_FILES = describeFileEntries(new VirtualFileSystem().allEntries());
|
||||
|
||||
/** Programs Swift's import drops and this one keeps (Java has them installed). */
|
||||
const PROGRAMS_SWIFT_DROPS = new Set(['commandPrompt', 'fileExplorer', 'imageViewer', 'textEditor', 'echoServer', 'simpleClient']);
|
||||
|
||||
/**
|
||||
* describeSystem's shape. A firewall as the core has it without one
|
||||
* (inactive, drop, no rules) is left out: Swift keeps a configuration only
|
||||
@@ -126,6 +130,23 @@ function systemOf(project: ImportedProject, nodeId: Id) {
|
||||
if (forwarding !== undefined) {
|
||||
result.portForwarding = forwarding.map((row) => [row.protocolValue, row.publicPortValue, row.lanIPAddress, row.lanPortValue]);
|
||||
}
|
||||
const programs = project.installedPrograms.get(nodeId);
|
||||
const kept = [...(programs ?? [])].filter((program) => !PROGRAMS_SWIFT_DROPS.has(program)).sort();
|
||||
if (kept.length > 0) result.installedPrograms = kept;
|
||||
const web = project.webServerConfigurations.get(nodeId);
|
||||
if (web !== undefined) {
|
||||
// Swift serves the same files from /www after moving them there.
|
||||
result.webServer = { port: web.port, documentRoot: web.documentRoot === '/webserver' ? '/www' : web.documentRoot, virtualHosts: false };
|
||||
}
|
||||
const gnutella = project.gnutellaConfigurations.get(nodeId);
|
||||
if (gnutella !== undefined) result.gnutella = gnutella;
|
||||
const dns = project.dnsServerConfigurations.get(nodeId);
|
||||
if (dns !== undefined) {
|
||||
result.dnsServer = {
|
||||
recursiveResolutionEnabled: dns.recursiveResolutionEnabled,
|
||||
forwardingServerIPAddress: dns.forwardingServerIPAddress ?? null,
|
||||
};
|
||||
}
|
||||
const remoteLink = project.remoteLinkConfigurations.get(nodeId);
|
||||
if (remoteLink !== undefined) result.remoteLink = remoteLink;
|
||||
const firewall = project.firewallConfigurationsByNodeId.get(nodeId);
|
||||
@@ -217,23 +238,27 @@ function withJavaDefaultNames(state: unknown): unknown {
|
||||
|
||||
/**
|
||||
* Where the Swift import is wrong and Java (corpus.java.json) is right, per
|
||||
* file and node: the corrected fields.
|
||||
* file and node: the corrected node.
|
||||
*/
|
||||
const SWIFT_ERRORS: Record<string, Record<number, { displayName: string; hostLabelPolicy: string }>> = {
|
||||
// useIPAsName is `<object idref="Boolean0"/>`, the shared result of a
|
||||
// button's isEnabled() — true. Swift's reader cannot follow it: it shows
|
||||
// the label text as a manual name instead of the IP address.
|
||||
type SwiftNode = { displayName: string; hostLabelPolicy: string; system: Record<string, unknown> };
|
||||
const shownByIp = (displayName: string) => (node: SwiftNode) => ({ ...node, displayName, hostLabelPolicy: 'ipAddress' });
|
||||
const SWIFT_ERRORS: Record<string, Record<number, (node: SwiftNode) => SwiftNode>> = {
|
||||
'java-examples/multicast_server.fls': {
|
||||
0: { displayName: 'Rechner', hostLabelPolicy: 'ipAddress' },
|
||||
1: { displayName: 'Notebook', hostLabelPolicy: 'ipAddress' },
|
||||
2: { displayName: 'Notebook', hostLabelPolicy: 'ipAddress' },
|
||||
// useIPAsName is `<object idref="Boolean0"/>`, the shared result of a
|
||||
// button's isEnabled() — true. Swift's reader cannot follow it: it shows
|
||||
// the label text as a manual name instead of the IP address.
|
||||
0: shownByIp('Rechner'),
|
||||
// maxTeilnehmerZahl is `<object idref="Integer0"/>`, the shared result of
|
||||
// a button's getIconTextGap() — 4. Swift falls back to its default 3.
|
||||
1: (node) => ({ ...shownByIp('Notebook')(node), system: { ...node.system, gnutella: { maximumKnownPeers: 4 } } }),
|
||||
2: shownByIp('Notebook'),
|
||||
},
|
||||
};
|
||||
|
||||
function withSwiftErrorsCorrected(name: string, state: unknown): unknown {
|
||||
const corrections = SWIFT_ERRORS[name] ?? {};
|
||||
const { nodes, ...rest } = state as { nodes: object[] };
|
||||
return { ...rest, nodes: nodes.map((node, index) => ({ ...node, ...corrections[index] })) };
|
||||
const { nodes, ...rest } = state as { nodes: SwiftNode[] };
|
||||
return { ...rest, nodes: nodes.map((node, index) => corrections[index]?.(node) ?? node) };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -716,6 +741,58 @@ describe('importProject rules', () => {
|
||||
expect(() => VirtualFileSystem.validateProjectQuotas(devices)).toThrow('totalSizeQuotaExceeded(100663296, 67108864)');
|
||||
});
|
||||
|
||||
it("keeps every installed program with its settings, and forwards DNS only to another server", () => {
|
||||
const source = flsNode('Rechner').source;
|
||||
const application = (javaClass: FlsApplication['javaClass'], fields: Partial<FlsApplication> = {}): FlsApplication => ({
|
||||
key: javaClass,
|
||||
javaClass,
|
||||
source,
|
||||
...fields,
|
||||
});
|
||||
const host = (dns: string, recursive: boolean) =>
|
||||
flsNode('Rechner', {
|
||||
interfaces: [{ ip: '10.0.0.1', mask: '255.255.255.0', mac: undefined, gateway: '', dns }],
|
||||
system: { applications: [application('filius.software.dns.DNSServer', { isActive: true, port: 53, recursiveResolutionEnabled: recursive })] },
|
||||
});
|
||||
const project = importProject(
|
||||
topology({
|
||||
nodes: [
|
||||
flsNode('Notebook', {
|
||||
interfaces: [nic('10.0.0.2')],
|
||||
system: {
|
||||
applications: [
|
||||
application('filius.software.lokal.Terminal'),
|
||||
application('filius.software.www.WebServer', { isActive: true, port: 8080, useVirtualHosts: false }),
|
||||
application('filius.software.clientserver.ServerBaustein', { isActive: false, port: 7 }),
|
||||
application('filius.software.clientserver.ClientBaustein', { targetAddress: ' 10.0.0.9 ', targetPort: 7 }),
|
||||
application('filius.software.firewall.Firewall', {
|
||||
firewall: { activated: true, defaultPolicy: 1, dropICMP: false, filterSYNSegmentsOnly: true, filterUdp: true, rules: [] },
|
||||
}),
|
||||
],
|
||||
},
|
||||
}),
|
||||
host('8.8.8.8', true),
|
||||
host('10.0.0.1', true),
|
||||
host('8.8.8.8', false),
|
||||
],
|
||||
}),
|
||||
counter(),
|
||||
);
|
||||
const [notebook, forwarding, self, iterative] = project.graph.nodes.map((node) => node.id);
|
||||
|
||||
expect([...project.installedPrograms.get(notebook!)!].sort()).toEqual(['commandPrompt', 'echoServer', 'firewall', 'simpleClient', 'webServer']);
|
||||
expect([...project.activePrograms.get(notebook!)!]).toEqual(['webServer']);
|
||||
expect(project.webServerConfigurations.get(notebook!)).toEqual({ port: 8080, documentRoot: '/webserver' });
|
||||
expect(project.echoServerConfigurations.get(notebook!)).toEqual({ port: 7 });
|
||||
expect(project.simpleClientConfigurations.get(notebook!)).toEqual({ targetAddress: '10.0.0.9', targetPort: 7 });
|
||||
expect(project.firewallConfigurationsByNodeId.get(notebook!)).toMatchObject({ isActive: true, defaultPolicy: 'accept' });
|
||||
expect([forwarding, self, iterative].map((id) => project.dnsServerConfigurations.get(id!))).toEqual([
|
||||
{ recursiveResolutionEnabled: true, forwardingServerIPAddress: '8.8.8.8' },
|
||||
{ recursiveResolutionEnabled: true },
|
||||
{ recursiveResolutionEnabled: false },
|
||||
]);
|
||||
});
|
||||
|
||||
it('leaves out a cable to itself and one to a port that already has a cable', () => {
|
||||
const project = importProject(
|
||||
topology({
|
||||
|
||||
Reference in New Issue
Block a user