7 Integration: Unified Pipeline and Token Injection

7.1 Architecture Overview

The three resource layers described in sec. 4, sec. 5, and sec. 6 are orchestrated by a single function in src/integration.py. The run_integration_demo() function calls all three subsystems in a defined order, collects their results into a structured dictionary, and writes summary counts to output/data/manuscript_variables.json for injection into this manuscript at render time. fig. 1 illustrates the complete architecture.

run_integration_demo()
  ├── read_bibliography_fond()       → {"manifest": ..., "bibtex": ..., "csv_rows": [...]}
  ├── read_contacts_fond()           → {"manifest": ..., "contacts": [...]}
  ├── read_datasets_fond()           → {"manifest": ..., "datasets": [...]}
  ├── validate_against_rules("template_project_rules")    → {"status": "ok", ...}
  ├── validate_against_rules("template_manuscript_rules") → {"status": "ok", ...}
  ├── discover_tools()               → [{"name": ..., "manifest": ...}, ...]
  └── validate_tool_scripts_exist(<each tool>)            → {"status": "ok", ...}

The function returns a top-level dict with keys fonds, rules, tools, and summary. The summary sub-dict provides the counts that populate manuscript tokens.

7.2 Manuscript Variable Tokens

The token injection system bridges the integration pipeline and the manuscript prose. Tokens use double-brace syntax: 3 expands to the integer count of fonds successfully loaded during the most recent integration run. The analysis script 03_generate_manuscript.py writes the current values. The Stage 03 hook z_generate_manuscript_variables.py regenerates those values and substitutes them into the rendered copy.

Bar chart comparing the runtime counts discovered for fonds, rules, and tools.
Figure 5: Runtime integration counts from manuscript_variables.json. Bars show fonds loaded, rule sets validated, and tools discovered during a single pipeline run.

The current manuscript_variables.json contains the following summary values (see fig. 5 for a visual representation):

Token Value
3 3
2 2
4 4
8 8

This table is itself token-injected: the values shown are those produced by the pipeline, not hard-coded by the manuscript author. If the pipeline results change — for example, because a new fond is added — re-running scripts/03_generate_manuscript.py updates the manuscript automatically, without manual editing. This property is central to reproducibility: the manuscript’s quantitative claims are always consistent with the code that generated them (Stodden et al. 2013).

7.3 Methods: The Script Pipeline

Six thin orchestration scripts govern the integration workflow (fig. 7, fig. 6):

Script Purpose Key output
scripts/01_validate_sources.py Validate presence and well-formedness of all resources Console report
scripts/02_run_integration.py Run run_integration_demo() and print JSON summary Console JSON
scripts/03_generate_manuscript.py Write output/data/manuscript_variables.json JSON file
scripts/04_validate_strong_rules.py Semantic evaluation of strong-rule constraints (sec. 5) against this project’s own tree Console report, non-zero exit on violation
scripts/05_generate_figures.py Render eight content figures plus the cover illustration PNG files under docs/manuscript/figures/
scripts/z_generate_manuscript_variables.py Hydrate declared manuscript-variable placeholders and inject them into output/manuscript/ immediately before rendering JSON file + resolved manuscript tree
Left-to-right pipeline from source validation through integration, figure generation, variable hydration, and publication rendering.
Figure 6: The six-script pipeline from source validation through token hydration, ending at the combined-PDF render step.
Status dashboard showing pass, partial, or missing state for each resource category.
Figure 7: Integration status dashboard showing per-resource validation results. Green indicates ok, amber indicates partial, red indicates missing.

fig. 6 traces this sequence left to right: source validation feeds the integration demo, whose summary feeds both the manuscript-variable token file and the strong-rule semantic evaluator; the figure-generation stage runs independently; and z_generate_manuscript_variables.py — invoked automatically by the rendering pipeline immediately before the PDF render step — is what actually substitutes every declared placeholder and writes the resolved manuscript that pandoc consumes. fig. 7 shows the corresponding per-component pass/partial/missing status from the same run.

Each script imports all business logic from src/ and stays free of computation of its own — even 01_validate_sources.py, the largest entry point in this project, is entirely CLI plumbing (argument parsing, console formatting) around calls into src/fonds_reader.py, src/rules_applier.py, and src/tools_invoker.py. This thin-orchestrator pattern (Wilson et al. 2014) ensures that all testable logic is in src/ under the configured project coverage gate, while the scripts themselves remain readable without a dedicated test suite of their own.

7.4 Resilience Design

The integration layer enforces resilience at three levels, corresponding to the three failure modes a monorepo integration pipeline encounters:

  1. Resource absence: A fond, rule set, or tool directory may not yet exist if the resource was created by a parallel agent that has not yet completed. All three reader modules return None or empty collections in this case, and run_integration_demo() reports the missing resource in the summary dict without raising.

  2. Schema malformation: A manifest may be present but contain invalid YAML or missing required fields. Readers catch yaml.YAMLError and return a degraded result (status="partial" in rule validation; None in fond reading) rather than propagating the parse error.

  3. Script absence: A tool may declare entrypoints in its manifest that have not yet been created. validate_tool_scripts_exist() detects this at discovery time and returns status="partial" with a list of missing script paths, so the pipeline can report the defect without attempting to invoke a non-existent script.

Layered flow showing resource absence, malformed data, and missing scripts with bounded fallback responses.
Figure 8: The integration layer’s three-level resilience design: resource absence, schema malformation, and script absence, each with its own graceful-degradation response.

This three-level resilience design reflects the principle that shared-resource pipelines should fail informatively rather than catastrophically — surfacing the cause of incompleteness in structured output that downstream consumers can act on (Taschuk and Wilson 2017). fig. 8 presents the three levels as a single funnel: each level’s failure mode and graceful-degradation response, read top to bottom in the order a pipeline run actually encounters them (resource discovery happens before schema parsing, which happens before script-existence checks).

7.5 Performance and Overhead

The readers check filesystem paths and parse YAML locally. Discovery checks basic structure, while the separate semantic evaluator tests concrete project evidence against strong rules (sec. 5). The integration targets a curated set of shared resources. The repository does not include throughput measurements for large resource collections.

7.6 Test Coverage

The suite tests real resource paths, YAML, and BibTeX. It includes property-based tests for input handling and a 90% coverage floor for src/. The test run reports the measured coverage. The end-to-end integration test checks the summary keys and values consumed by token hydration. A separate negative control verifies that changed integration results change the emitted tokens.