Files
mdg-filius/packages/fls/test/ownApplications.ts
T
julian.kiedaischandClaude Opus 5.5 c8f2e9e225 feat(fls): a project's own applications through the editor model
The model carries the captured beans of a project's own applications
(ownApplicationsByNodeId); the export writes them again on the system
software of their node, and their classes go with the archive's other
entries. Checked by Java: from the exported files FILIUS loads
Accumulator and Broadcast as from the original; the export test no longer
leaves own applications out, and a probe that drops them is caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 09:44:39 +00:00

63 lines
2.3 KiB
TypeScript

// A project's own applications (classes under projekt/anwendungen): Java
// installs them when it loads the whole archive (tools/java-oracle, laden).
// The reader keeps them as beans, without knowing what Java makes of them;
// its test compares them by key and class.
import { FILIUS_APPLICATION_CLASSES } from '../src/index.js';
/** The corpus files with an own application installed on a host. */
export const OWN_APPLICATION_FILES = ['java-examples/anwendung_komplett.fls', 'java-examples/multicast_server.fls'];
type View = { nodes?: { system: Record<string, unknown> }[] };
/** Java's view without the applications FILIUS does not ship. */
function withoutOwnApplications<T>(view: T): T {
const { nodes } = view as View;
if (nodes === undefined) return view;
return {
...view,
nodes: nodes.map((node) =>
node.system.applications === undefined
? node
: {
...node,
system: {
...node.system,
applications: (node.system.applications as { class: string }[]).filter((application) =>
(FILIUS_APPLICATION_CLASSES as readonly string[]).includes(application.class),
),
},
},
),
};
}
/** Java's view with each own application as its key, class and whether it runs on its node's system software. */
export function withOwnApplicationsByClass<T>(view: T): T {
const { nodes } = view as View;
if (nodes === undefined) return view;
return {
...view,
nodes: nodes.map((node) =>
node.system.applications === undefined
? node
: {
...node,
system: {
...node.system,
applications: (node.system.applications as { key: string; class: string }[]).map((application) =>
(FILIUS_APPLICATION_CLASSES as readonly string[]).includes(application.class)
? application
: { key: application.key, class: application.class, onItsSystem: (application as { onItsSystem?: boolean }).onItsSystem },
),
},
},
),
};
}
/** Whether Java's view has an own application installed. */
export function hasOwnApplications(view: unknown): boolean {
return JSON.stringify(withoutOwnApplications(view)) !== JSON.stringify(view);
}