diff --git a/changelog.d/be-unit-declarations.added.md b/changelog.d/be-unit-declarations.added.md new file mode 100644 index 0000000000..bd80ceb601 --- /dev/null +++ b/changelog.d/be-unit-declarations.added.md @@ -0,0 +1 @@ +Add Belgium's declared family benefit unit (W3-R1), still inactive. `build/be/unit_declarations.json` is a `microcosm.multi_unit_rule.v1` document for `transport.create@2` with one `benefit_unit`, `family_benefit_unit`: an adult, a co-resident partner and their co-resident dependent children (persons aged 24 or under with no co-resident partner or child, other than a household reference person who has no co-resident parent), with a dependent child who has no co-resident parent placed in the unit that holds the household's reference person. It is built from options `BenefitUnitRule` already has. `axiom_rules_bindings.json` names the entity in `entity_names` under the engine name `FamilyBenefitUnit`, which no rulespec-be module declares at the pinned commit `632e1da1`. Ten input-closure reasons now say that W3's income node decides whether it sums over the declared unit or the survey household, in place of a unit that no pull request defined. Belgium has no transport graph, so nothing builds these units yet, and activation still refuses. Every value is a proposal that awaits Max's METHOD-CARD-BE ruling. diff --git a/packages/microcosm-build/src/microcosm/build/be/axiom_input_closure.json b/packages/microcosm-build/src/microcosm/build/be/axiom_input_closure.json index 4cf63b1d95..0907e9841d 100644 --- a/packages/microcosm-build/src/microcosm/build/be/axiom_input_closure.json +++ b/packages/microcosm-build/src/microcosm/build/be/axiom_input_closure.json @@ -277,7 +277,7 @@ "input": "brussels_family_benefits_social_supplement_household_annual_income", "class": "defaulted", "value": 45000.0, - "reason": "No income reaches the Child entity until W3 derives household income over the allocataire's unit (PR 3). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", + "reason": "No income reaches the Child entity until W3's income node derives household income for each child, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", "citation": "Brussels ordinance of 25 April 2019 regulating family benefits, article 9 (brussels_family_benefits_article_9_social_supplement_monthly_amount, social_supplements.yaml); the rule records no corpus_citation_path of its own, the module's source_verification gives be-bru/statute/ordonnance/2019/04/25/2019012118/article/9", "new_default": true }, @@ -348,7 +348,7 @@ "input": "brussels_family_benefits_social_supplement_household_annual_income", "class": "defaulted", "value": 45000.0, - "reason": "No income reaches the Child entity until W3 derives household income over the allocataire's unit (PR 3). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", + "reason": "No income reaches the Child entity until W3's income node derives household income for each child, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", "citation": "Brussels ordinance of 25 April 2019 regulating family benefits, article 9 (brussels_family_benefits_article_9_social_supplement_monthly_amount, social_supplements.yaml); the rule records no corpus_citation_path of its own, the module's source_verification gives be-bru/statute/ordonnance/2019/04/25/2019012118/article/9", "new_default": true }, @@ -395,7 +395,7 @@ "input": "brussels_family_benefits_social_supplement_household_annual_income", "class": "defaulted", "value": 45000.0, - "reason": "No income reaches the Child entity until W3 derives household income over the allocataire's unit (PR 3). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", + "reason": "No income reaches the Child entity until W3's income node derives household income for each child, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", "citation": "Brussels ordinance of 25 April 2019 regulating family benefits, article 9 (brussels_family_benefits_article_9_social_supplement_monthly_amount, social_supplements.yaml); the rule records no corpus_citation_path of its own, the module's source_verification gives be-bru/statute/ordonnance/2019/04/25/2019012118/article/9", "new_default": true }, @@ -856,7 +856,7 @@ "input": "flanders_family_benefits_family_annual_income", "class": "defaulted", "value": 70000.0, - "reason": "No income exists for the beneficiaries' family until W3's income node builds it over the legal unit PR 3 defines. 70000 exceeds the article 18 middle threshold (flanders_family_benefits_social_middle_income_threshold is 60000 at rulespec-be 632e1da1), so at those unindexed thresholds the social supplement pays nothing for any family size: a lower bound that leaves out every low-income supplement. The module's own base-amount test supplies the same value.", + "reason": "No income exists for the beneficiaries' family until W3's income node builds it, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). 70000 exceeds the article 18 middle threshold (flanders_family_benefits_social_middle_income_threshold is 60000 at rulespec-be 632e1da1), so at those unindexed thresholds the social supplement pays nothing for any family size: a lower bound that leaves out every low-income supplement. The module's own base-amount test supplies the same value.", "citation": "Flemish decree of 27 April 2018 regulating family-policy allowances, article 18 (flanders_family_benefits_social_supplement_before_shared_housing_monthly_amount); corpus_citation_path be-vlg/statute/decreet/2018/04/27/2018040369/article/18, recorded on the threshold and amount parameters the rule reads, not on the rule", "new_default": true }, @@ -1057,7 +1057,7 @@ "input": "flanders_family_benefits_family_annual_income", "class": "defaulted", "value": 70000.0, - "reason": "No income exists for the beneficiaries' family until W3's income node builds it over the legal unit PR 3 defines. 70000 exceeds the article 18 middle threshold (flanders_family_benefits_social_middle_income_threshold is 60000 at rulespec-be 632e1da1), so at those unindexed thresholds the social supplement pays nothing for any family size: a lower bound that leaves out every low-income supplement. The module's own base-amount test supplies the same value.", + "reason": "No income exists for the beneficiaries' family until W3's income node builds it, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). 70000 exceeds the article 18 middle threshold (flanders_family_benefits_social_middle_income_threshold is 60000 at rulespec-be 632e1da1), so at those unindexed thresholds the social supplement pays nothing for any family size: a lower bound that leaves out every low-income supplement. The module's own base-amount test supplies the same value.", "citation": "Flemish decree of 27 April 2018 regulating family-policy allowances, article 18 (flanders_family_benefits_social_supplement_before_shared_housing_monthly_amount); corpus_citation_path be-vlg/statute/decreet/2018/04/27/2018040369/article/18, recorded on the threshold and amount parameters the rule reads, not on the rule", "new_default": true }, @@ -1161,7 +1161,7 @@ "input": "wallonia_family_benefits_household_annual_income", "class": "defaulted", "value": 70000.0, - "reason": "No income node exists yet. 70,000 exceeds the 50,000 upper ceiling (wallonia_family_benefits_income_middle_threshold at rulespec-be 632e1da1), so the large-family and single-parent supplements and the income-tested social supplement all pay 0 (the 65 EUR article 14 supplement for a household with a disabled member reads no income, and its own default withholds it), and the child gets the base amount alone, as in the module's own base-only test case. W3's income node, built over the legal unit around the allocataire, will replace it; until then the default understates spending on households under the ceilings.", + "reason": "No income node exists yet. 70,000 exceeds the 50,000 upper ceiling (wallonia_family_benefits_income_middle_threshold at rulespec-be 632e1da1), so the large-family and single-parent supplements and the income-tested social supplement all pay 0 (the 65 EUR article 14 supplement for a household with a disabled member reads no income, and its own default withholds it), and the child gets the base amount alone, as in the module's own base-only test case. W3's income node, built over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE), will replace it; until then the default understates spending on households under the ceilings.", "citation": "Walloon decree of 8 February 2018 on management and payment of family benefits, articles 11, 12, 13 and 14 (wallonia_family_benefits_large_family_supplement_monthly_amount, wallonia_family_benefits_single_parent_supplement_monthly_amount, wallonia_family_benefits_social_or_disabled_household_member_supplement_monthly_amount); corpus_citation_path be-wal/statute/decret/2018/02/08/2018201006/article/13 (recorded on the two income-threshold parameters)", "new_default": true }, @@ -1439,7 +1439,7 @@ "input": "wallonia_family_benefits_household_annual_income", "class": "defaulted", "value": 70000.0, - "reason": "No income node exists yet. 70,000 exceeds the 50,000 upper ceiling (wallonia_family_benefits_income_middle_threshold at rulespec-be 632e1da1), so the large-family and single-parent supplements and the income-tested social supplement all pay 0 (the 65 EUR article 14 supplement for a household with a disabled member reads no income, and its own default withholds it), and the child gets the base amount alone, as in the module's own base-only test case. W3's income node, built over the legal unit around the allocataire, will replace it; until then the default understates spending on households under the ceilings.", + "reason": "No income node exists yet. 70,000 exceeds the 50,000 upper ceiling (wallonia_family_benefits_income_middle_threshold at rulespec-be 632e1da1), so the large-family and single-parent supplements and the income-tested social supplement all pay 0 (the 65 EUR article 14 supplement for a household with a disabled member reads no income, and its own default withholds it), and the child gets the base amount alone, as in the module's own base-only test case. W3's income node, built over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE), will replace it; until then the default understates spending on households under the ceilings.", "citation": "Walloon decree of 8 February 2018 on management and payment of family benefits, articles 11, 12, 13 and 14 (wallonia_family_benefits_large_family_supplement_monthly_amount, wallonia_family_benefits_single_parent_supplement_monthly_amount, wallonia_family_benefits_social_or_disabled_household_member_supplement_monthly_amount); corpus_citation_path be-wal/statute/decret/2018/02/08/2018201006/article/13 (recorded on the two income-threshold parameters)", "new_default": true }, @@ -1888,7 +1888,7 @@ "input": "brussels_family_benefits_social_supplement_household_annual_income", "class": "defaulted", "value": 45000.0, - "reason": "No income reaches the Child entity until W3 derives household income over the allocataire's unit (PR 3). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", + "reason": "No income reaches the Child entity until W3's income node derives household income for each child, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). Set at the article 9, 2\u00b0 upper bound (brussels_family_benefits_social_supplement_middle_income_upper_bound is 45000 at rulespec-be 632e1da), so both `income < bound` tests fail and no child receives a social supplement: a lower bound on spending.", "citation": "Brussels ordinance of 25 April 2019 regulating family benefits, article 9 (brussels_family_benefits_article_9_social_supplement_monthly_amount, social_supplements.yaml); the rule records no corpus_citation_path of its own, the module's source_verification gives be-bru/statute/ordonnance/2019/04/25/2019012118/article/9", "new_default": true }, @@ -2059,7 +2059,7 @@ "input": "flanders_family_benefits_family_annual_income", "class": "defaulted", "value": 70000.0, - "reason": "No income exists for the beneficiaries' family until W3's income node builds it over the legal unit PR 3 defines. 70000 exceeds the article 18 middle threshold (flanders_family_benefits_social_middle_income_threshold is 60000 at rulespec-be 632e1da1), so at those unindexed thresholds the social supplement pays nothing for any family size: a lower bound that leaves out every low-income supplement. The module's own base-amount test supplies the same value.", + "reason": "No income exists for the beneficiaries' family until W3's income node builds it, over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE). 70000 exceeds the article 18 middle threshold (flanders_family_benefits_social_middle_income_threshold is 60000 at rulespec-be 632e1da1), so at those unindexed thresholds the social supplement pays nothing for any family size: a lower bound that leaves out every low-income supplement. The module's own base-amount test supplies the same value.", "citation": "Flemish decree of 27 April 2018 regulating family-policy allowances, article 18 (flanders_family_benefits_social_supplement_before_shared_housing_monthly_amount); corpus_citation_path be-vlg/statute/decreet/2018/04/27/2018040369/article/18, recorded on the threshold and amount parameters the rule reads, not on the rule", "new_default": true }, @@ -2641,7 +2641,7 @@ "input": "wallonia_family_benefits_household_annual_income", "class": "defaulted", "value": 70000.0, - "reason": "No income node exists yet. 70,000 exceeds the 50,000 upper ceiling (wallonia_family_benefits_income_middle_threshold at rulespec-be 632e1da1), so the large-family and single-parent supplements and the income-tested social supplement all pay 0 (the 65 EUR article 14 supplement for a household with a disabled member reads no income, and its own default withholds it), and the child gets the base amount alone, as in the module's own base-only test case. W3's income node, built over the legal unit around the allocataire, will replace it; until then the default understates spending on households under the ceilings.", + "reason": "No income node exists yet. 70,000 exceeds the 50,000 upper ceiling (wallonia_family_benefits_income_middle_threshold at rulespec-be 632e1da1), so the large-family and single-parent supplements and the income-tested social supplement all pay 0 (the 65 EUR article 14 supplement for a household with a disabled member reads no income, and its own default withholds it), and the child gets the base amount alone, as in the module's own base-only test case. W3's income node, built over the family benefit unit that unit_declarations.json declares or over the survey household, as that node's declaration decides (METHOD-CARD-BE), will replace it; until then the default understates spending on households under the ceilings.", "citation": "Walloon decree of 8 February 2018 on management and payment of family benefits, articles 11, 12, 13 and 14 (wallonia_family_benefits_large_family_supplement_monthly_amount, wallonia_family_benefits_single_parent_supplement_monthly_amount, wallonia_family_benefits_social_or_disabled_household_member_supplement_monthly_amount); corpus_citation_path be-wal/statute/decret/2018/02/08/2018201006/article/13 (recorded on the two income-threshold parameters)", "new_default": true }, diff --git a/packages/microcosm-build/src/microcosm/build/be/axiom_rules_bindings.json b/packages/microcosm-build/src/microcosm/build/be/axiom_rules_bindings.json index cd4b572b99..2c75d8c743 100644 --- a/packages/microcosm-build/src/microcosm/build/be/axiom_rules_bindings.json +++ b/packages/microcosm-build/src/microcosm/build/be/axiom_rules_bindings.json @@ -14,13 +14,14 @@ "repository": "TheAxiomFoundation/axiom-rules-engine", "commit": "753ce7d9ac4cfb161f6aa4f281f5a3980e67a57d", "wheel_sha256": "054c9196d5371f13bb7c2b28f8161ac92294e5c8543aeb6e221fde243897ed42", - "status": "Pinned at New Zealand's engine pin (nz/axiom_rules_bindings.json). commit is the axiom-rules-engine commit that Belgium's input surface and input closure record. wheel_sha256 is the SHA-256 of the dense-extension wheel the NZ hub built at that commit (CPython 3.14, macOS arm64), the wheel whose extension generated Belgium's input surface. axiom_engine_ref records both as declared and hashes no installed wheel. build_transport_registry also needs the unit entity that entity_names_note describes, so no registry builds from this file before it lands." + "status": "Pinned at New Zealand's engine pin (nz/axiom_rules_bindings.json). commit is the axiom-rules-engine commit that Belgium's input surface and input closure record. wheel_sha256 is the SHA-256 of the dense-extension wheel the NZ hub built at that commit (CPython 3.14, macOS arm64), the wheel whose extension generated Belgium's input surface. axiom_engine_ref records both as declared and hashes no installed wheel. build_transport_registry also needs the unit declaration (unit_declarations.json), whose entity entity_names holds (entity_names_note). Nothing builds a registry from this file until a transport graph exists." }, "entity_names": { "person": "Person", - "household": "Household" + "household": "Household", + "family_benefit_unit": "FamilyBenefitUnit" }, - "entity_names_note": "entity_names holds the two frame entities the axiom:be mapping maps. build_transport_registry requires it to name exactly the transport schema's entities: person, household and each unit entity the benefit unit rule declares (transport/registry.py, build_transport_registry; frame/unit_construction.py, MultiUnitRule.entity_schema). Belgium has no benefit_unit_rule.json yet. The change that adds it also adds its entity here, under an engine name other than Child, since the registry refuses a view whose logical entity a frame entity maps to.", + "entity_names_note": "entity_names names exactly the transport schema's entities, as build_transport_registry requires: person, household and each unit entity that unit_declarations.json declares (transport/registry.py, build_transport_registry; frame/unit_construction.py, MultiUnitRule.entity_schema). person and household are the two frame entities the axiom:be mapping maps. family_benefit_unit is the benefit unit that unit_declarations.json declares for transport.create@2. Its engine name, FamilyBenefitUnit, is one that no rulespec-be module declares at the pin, so no rule output lands on an entity of that name, and the committed files attach no group binding to the unit. The name does not stop a later concepts.encode_groups@1 node from encoding Family's group bindings over this unit's members, since that node names its engine entity and its unit separately (transport/column_kernels.py); whether one does is that node's choice. It is not Child, since the registry refuses a view whose logical entity a frame entity maps to. It is not Family either. At the pin that entity carries the pension-sector withholdings in be/statutes/social_security/non_labour_income_contributions.yaml (article 68 solidarity, article 191 health insurance and Royal Decree No. 33), and the axiom:be mapping holds eight Family bindings, each a sum over a unit's members. This declaration does not compare its unit with the unit those rules assume, so it does not take their name. Who belongs to the unit is a method choice that METHOD-CARD-BE records (decision d1902). The declaration is inactive until a transport graph holds a transport.create@2 node that selects it. While the graph holds no transport.create@2 node at all, activation reports benefit_unit_rule.json as missing; once it holds one, activation checks that node's own unit declaration instead (transport/compose.py, validate_transport_activation).", "periods": { "2026-01": { "kind": "calendar_month", diff --git a/packages/microcosm-build/src/microcosm/build/be/country_package.json b/packages/microcosm-build/src/microcosm/build/be/country_package.json index f487c41c30..e3f74791f5 100644 --- a/packages/microcosm-build/src/microcosm/build/be/country_package.json +++ b/packages/microcosm-build/src/microcosm/build/be/country_package.json @@ -111,6 +111,11 @@ "path": "target_references.json", "kind": "legacy_json", "schema_id": "legacy_json" + }, + { + "path": "unit_declarations.json", + "kind": "legacy_json", + "schema_id": "legacy_json" } ] } diff --git a/packages/microcosm-build/src/microcosm/build/be/unit_declarations.json b/packages/microcosm-build/src/microcosm/build/be/unit_declarations.json new file mode 100644 index 0000000000..8d43036ebf --- /dev/null +++ b/packages/microcosm-build/src/microcosm/build/be/unit_declarations.json @@ -0,0 +1,34 @@ +{ + "format": "microcosm.multi_unit_rule.v1", + "units": [ + { + "kind": "benefit_unit", + "rule": { + "format": "microcosm.benefit_unit_rule.v1", + "entity": "family_benefit_unit", + "dependent_child": { + "max_age": 24, + "parent_independence_min_age": null, + "financial_independence": null + }, + "unparented_child": "reference_person_unit", + "split_parents": "first_parent_unit", + "refuse_dependent_reference_person": false, + "provenance": { + "status": "Every value in this rule was put to Max as a proposal for METHOD-CARD-BE, the Belgium port's method card, under decision d1902. The card is kept with the port's notes outside this repository and records whether Max adopted each value. No value is a statement of Belgian law.", + "unit": "One adult, that adult's co-resident partner and their co-resident dependent children. A dependent child is a person aged 24 or under who has no co-resident partner and no co-resident child, other than a household reference person who has no co-resident parent. An adult is any other person, at any age. The unit that holds the household's reference person also takes each dependent child who has no co-resident parent (unparented_child). Every other adult in the household anchors a unit of their own. The unit is a co-residence stand-in for the persons a regional family-benefit income test and child count look at. rulespec-be at 632e1da1110ba881c68165e0cd3c2287b5b8ab08 takes those incomes and counts as supplied inputs and defines no membership.", + "entity": "family_benefit_unit names the partition after the schemes it serves. axiom_rules_bindings.json gives it the engine name FamilyBenefitUnit, which no rulespec-be module declares at that commit, so no rule there computes on an entity of that name. A later group node could still encode another entity's group bindings, such as Family's, over this unit's members; whether one does is that node's choice. The regional family-benefit modules at that commit run on Child, so a unit fact reaches them only as a person column that a graph supplies.", + "max_age": "24. A person aged 24 or under can be a dependent child. In each of the four regional family-benefit eligibility modules at that commit the last age parameter is 25, read with a strict comparison: flanders_family_benefits_student_age_limit_years, brussels_family_benefits_article_25_extended_age_limit_years, wallonia_family_benefits_extended_age_years and german_speaking_community_family_benefits_final_age_cap_years. Below that, the Walloon module also meets its age condition for a person under 21, with no study test, when wallonia_family_benefits_no_government_obstacle_applies holds. So the limit takes no person whom those age parameters admit out of the unit of a parent they live with. Three supplied conditions can entitle a person aged 25 or over when each means what its name says: flanders_family_benefits_child_in_month_turning_25, flanders_family_benefits_book_5_transition_no_age_limit_applies and brussels_family_benefits_article_26_condition_met. The modules read those conditions, and their other birthday-month flags, without checking them against the supplied age. A person aged 25 or over is never a dependent child, so one whom such a condition entitles anchors a unit, alone or with a partner. The limit decides no entitlement; the modules do.", + "financial_independence": "None. An hours test needs a Belgian threshold, and no source read for this declaration gives one. Without a test the constructor reads no usual weekly hours. A working person aged 24 or under who has no partner and no co-resident child and lives with a parent stays in parent 1's unit, and the modules decide whether that person is entitled.", + "parent_independence_min_age": "None, the constructor's default. A parent of a co-resident child anchors a unit at any age, apart from that parent's own parents. A minor parent's dependent child joins that unit when the minor is the child's parent 1 or is the partner of parent 1; otherwise the child follows parent 1 (split_parents).", + "unparented_child": "reference_person_unit. A person aged 24 or under who has no co-resident parent, no co-resident partner and no co-resident child, and who is not the household's reference person, joins the unit that holds the reference person, whoever in the household raises that person. This is an assumption. Its one source covers the German-speaking Community only: article 28 of the decree of 23 April 2018, as published in the Moniteur belge of 12 June 2018 and held in the rulespec-be corpus at that commit (later amendments were not read). After any person a court designates and any parent who shares the child's domicile, that article names the person who actually raises the child, meaning whoever bears more than half of the child's maintenance costs, and presumes until proven otherwise that the adults who share the child's domicile do. It picks a recipient, not a unit, and does not single out the reference person. A flatmate or lodger aged 24 or under whom the donor records with no co-resident parent, partner or child lands in the reference person's unit too: a disclosed approximation, because one policy covers every age. One recorded with a co-resident partner or child is an adult, as the unit key defines it, so this option does not place them, and one recorded with a co-resident parent but no partner or child joins parent 1's unit.", + "split_parents": "first_parent_unit. A dependent child whose two co-resident parents are not partners of each other joins parent 1's unit; the other value refuses any frame that holds such a child. A partition holds each child once, so it cannot give one child a place in two families, and flanders_family_benefits_equal_shared_housing stays a separate input.", + "refuse_dependent_reference_person": "false. A reference person aged 24 or under with no co-resident parent anchors a unit. True would refuse the whole frame in two cases: a reference person aged 24 or under who has no co-resident parent, no partner and no co-resident child; and a reference person who is a dependent child of a co-resident parent, in a household that also holds a dependent child with no co-resident parent.", + "head": "The unit's head is a construction label: the household reference person when that person is an adult of the unit, otherwise the older adult, or the one with the smaller person id when their ages are equal. This rule names no allocataire and no payee.", + "donor_pointers": "Membership is only as good as the donor's pointers. Cohabiting partners with no partner pointer are not paired. When their dependent child names both as parents, the child joins parent 1's unit, that unit reads as a single parent's, and parent 2 anchors another unit. A cohabitant with no pointer is classified like any other unpartnered person, so one aged 24 or under whom no co-resident person names as a parent can read as a dependent child. A partner or parent who lives elsewhere is not seen at all.", + "not_expressed": "The constructor reads age, the partner and parent pointers and the household reference person. It reads no legal marital status, no enrolment, no income, no court designation and nobody outside the household. A partner pointer stands for a spouse or a cohabiting partner alike, where the donor records one (donor_pointers). Whether an income test sums over this unit's adults, over all its members or over the household is decided where the income node is declared, not here." + } + } + } + ] +} diff --git a/packages/microcosm-build/tests/engine_free/shared/test_be_unit_declarations.py b/packages/microcosm-build/tests/engine_free/shared/test_be_unit_declarations.py new file mode 100644 index 0000000000..8cd4db2760 --- /dev/null +++ b/packages/microcosm-build/tests/engine_free/shared/test_be_unit_declarations.py @@ -0,0 +1,329 @@ +"""Belgium's declared family benefit unit (W3-R1), still inactive. + +``build/be/unit_declarations.json`` is a ``microcosm.multi_unit_rule.v1`` +document for ``transport.create@2``. Belgium has no transport graph, so +nothing builds units from it yet. These tests pin what the declaration says, +that the bindings' ``entity_names`` matches its schema as the registry +requires, that a ``transport.create@2`` node can select it, that no income +default still ties the unit to another pull request, and what it does to a +few households. A property over generated valid frames pins who is a +dependent child and which unit each dependent child joins. Every value is a +METHOD-CARD-BE proposal under d1902. +""" + +import copy +import json +from collections import Counter + +import numpy as np +import pandas as pd +import pytest +from hypothesis import given, settings +from hypothesis import strategies as st + +from microcosm.build.transport.compose import ( + load_transport_spec, + validate_transport_activation, +) +from microcosm.build.transport.registry import transport_entity_schema +from microcosm.build.transport.unit_declarations import ( + CREATE_V1_REF, + CREATE_V2_REF, + create_unit_declaration, +) +from microcosm.frame.adapters.axiom import axiom_concept_mapping +from microcosm.frame.adapters.axiom_input_surface import load_axiom_input_surface +from microcosm.frame.unit_construction import build_declared_units +from test_support.microcosm_frame.concept_frames import concept_frames +from test_support.paths import paths_for + +_BE = paths_for("microcosm-build").package / "src/microcosm/build/be" +_SURFACE = paths_for("microcosm-frame").tests / "fixtures/axiom_input_surfaces/be.json" +UNITS_PATH = _BE / "unit_declarations.json" +ENTITY, ENGINE = "family_benefit_unit", "FamilyBenefitUnit" + + +def _document() -> dict: + return json.loads(UNITS_PATH.read_text(encoding="utf-8")) + + +def _declaration(): + return create_unit_declaration(CREATE_V2_REF, _document()) + + +def test_the_document_is_one_benefit_unit_for_create_2() -> None: + declaration = _declaration() + assert [(unit.kind, unit.entity) for unit in declaration.units] == [ + ("benefit_unit", ENTITY) + ] + # Strict format: the file is exactly what the rule serializes to, so no + # value rests on a parser default. + assert declaration.to_dict() == _document() + assert UNITS_PATH.read_text(encoding="ascii") == ( + json.dumps(_document(), indent=2) + "\n" + ) + # create@1 takes one family rule, never this document. + with pytest.raises(ValueError): + create_unit_declaration(CREATE_V1_REF, _document()) + + +def test_the_rule_states_the_method_card_proposal() -> None: + rule = _declaration().units[0].rule + child = rule.dependent_child + assert child.max_age == 24 + assert child.financial_independence is None + assert child.parent_independence_min_age is None + assert rule.unparented_child.value == "reference_person_unit" + assert rule.split_parents.value == "first_parent_unit" + assert rule.refuse_dependent_reference_person is False + # The status says where the values were proposed and where the ruling is + # recorded, in words that stay true after the ruling: a later edit to + # this text would re-key a transport.create@2 node that reads the file. + status = rule.provenance["status"] + assert "d1902" in status + assert "METHOD-CARD-BE" in status + assert "as a proposal" in status + assert "records whether Max adopted each value" in status + assert "No value is a statement of Belgian law" in status + # Each declared option carries its reason. + assert { + "max_age", + "financial_independence", + "parent_independence_min_age", + "unparented_child", + "split_parents", + "refuse_dependent_reference_person", + } <= set(rule.provenance) + + +def test_entity_names_cover_exactly_the_declared_schema() -> None: + # The conditions build_transport_registry puts on entity_names + # (transport/registry.py), restated on the committed files: the schema's + # entities exactly, each name a non-empty string, all names distinct. + schema, nesting = transport_entity_schema(_declaration()) + names = json.loads((_BE / "axiom_rules_bindings.json").read_text())["entity_names"] + assert set(names) == set(schema.entities) == {"person", "household", ENTITY} + assert dict(nesting) == {ENTITY: "household"} + assert all(isinstance(name, str) and name for name in names.values()) + assert len(set(names.values())) == len(names) + assert names[ENTITY] == ENGINE + assert "Child" not in names.values() + + +def test_the_engine_name_carries_no_input_and_no_binding() -> None: + # What the committed files can show: no concept binding, no person-role + # entity, no transport binding row or view, and no root input recorded in + # the committed input surface names this entity. Rule outputs are not in + # these files; that no rulespec-be module declares the entity was read at + # the pinned commit, not tested here. + mapping = axiom_concept_mapping("be") + surface = load_axiom_input_surface(_SURFACE) + assert ENGINE not in mapping.entity_correspondence.values() + assert ENGINE not in mapping.person_role_entities() + assert all(binding.engine_entity != ENGINE for binding in mapping.bindings) + assert all(ENGINE not in module.inputs for module in surface.modules.values()) + rows = json.loads((_BE / "axiom_rules_bindings.json").read_text())["bindings"] + assert rows + for row in rows: + assert row["engine_entity"] != ENGINE + # The registry accepts a row with no views. + views = row.get("views", ()) + assert all(view["logical_entity"] != ENGINE for view in views) + + +def test_a_create_2_node_can_select_the_declaration() -> None: + spec = load_transport_spec(_BE) + with pytest.raises(ValueError, match="not activated") as before: + validate_transport_activation(spec) + # No create@2 node yet, so activation still asks for the create@1 resource. + assert "benefit_unit_rule.json" in str(before.value) + stub = copy.deepcopy(spec) + stub["resources"]["transport_graph"] = { + "schema_version": 1, + "country": "be", + "nodes": [ + { + "id": "be.create", + "kernel": CREATE_V2_REF, + "structural": "create", + "params": { + "unit_rule": {"resource": "unit_declarations", "encoding": "json"} + }, + } + ], + } + with pytest.raises(ValueError, match="not activated") as after: + validate_transport_activation(stub) + assert "benefit_unit_rule.json" not in str(after.value) + assert "unit declarations" not in str(after.value) + # Activation reads the node's own declaration, not the file's presence: a + # create@2 node with no unit_rule is refused on that gap. + broken = copy.deepcopy(stub) + del broken["resources"]["transport_graph"]["nodes"][0]["params"]["unit_rule"] + with pytest.raises(ValueError, match="not activated") as refused: + validate_transport_activation(broken) + assert "benefit_unit_rule.json" not in str(refused.value) + assert "unit declarations:" in str(refused.value) + # A selected declaration that is present but fails the parser is refused + # on the declaration itself, so activation parses what the node selects. + unparsed = copy.deepcopy(stub) + unparsed["resources"]["unit_declarations"]["format"] = "microcosm.unit_rule.v0" + with pytest.raises(ValueError, match="not activated") as invalid: + validate_transport_activation(unparsed) + assert "unit declarations: Declared units must declare format" in str(invalid.value) + + +def test_no_income_default_ties_the_unit_to_another_pull_request() -> None: + closure = json.loads((_BE / "axiom_input_closure.json").read_text()) + reasons = [entry["reason"] for entry in closure["entries"] if "reason" in entry] + assert not [reason for reason in reasons if "PR 3" in reason] + assert not [reason for reason in reasons if "legal unit" in reason] + naming = [ + entry + for entry in closure["entries"] + if UNITS_PATH.name in entry.get("reason", "") + ] + assert Counter(entry["input"] for entry in naming) == { + "brussels_family_benefits_social_supplement_household_annual_income": 4, + "flanders_family_benefits_family_annual_income": 3, + "wallonia_family_benefits_household_annual_income": 3, + } + # Each leaves the income node to decide whether it sums over the unit or + # the household, as the declaration's not_expressed note says. + assert all( + "over the family benefit unit that unit_declarations.json declares or " + "over the survey household, as that node's declaration decides" + in entry["reason"] + for entry in naming + ) + + +NA = pd.NA +# (person_id, household, age, partner, parent_1, parent_2, unit, role) +PEOPLE = [ + (101, 1, 44, 102, NA, NA, 101, "head"), + (102, 1, 42, 101, NA, NA, 101, "partner"), + (103, 1, 3, NA, 101, 102, 101, "dependent_child"), + (104, 1, 13, NA, 101, 102, 101, "dependent_child"), + (105, 1, 20, NA, 101, 102, 101, "dependent_child"), + (107, 1, 24, NA, 101, 102, 101, "dependent_child"), # the last age inside + (106, 1, 25, NA, 101, 102, 106, "head"), # past the age limit + (201, 2, 70, NA, NA, NA, 201, "head"), # three generations: two units + (202, 2, 22, NA, 201, NA, 202, "head"), + (203, 2, 2, NA, 202, NA, 202, "dependent_child"), + (301, 3, 50, NA, NA, NA, 301, "head"), + (302, 3, 10, NA, NA, NA, 301, "dependent_child"), # no co-resident parent + (401, 4, 30, NA, NA, NA, 401, "head"), + (402, 4, 22, NA, NA, NA, 401, "dependent_child"), # the disclosed approximation + (501, 5, 35, NA, NA, NA, 501, "head"), + (502, 5, 36, NA, NA, NA, 502, "head"), + (503, 5, 6, NA, 501, 502, 501, "dependent_child"), # non-partner co-parents + (601, 6, 23, NA, NA, NA, 601, "head"), # a young reference person alone + (700, 7, 45, NA, NA, NA, 700, "head"), + (701, 7, 17, NA, 700, NA, 701, "head"), # a minor parent anchors a unit + (702, 7, 1, NA, 701, NA, 701, "dependent_child"), + (801, 8, 21, 802, 803, NA, 802, "partner"), # partnered: never a dependent + (802, 8, 23, 801, NA, NA, 802, "head"), # the older adult of the couple + (803, 8, 55, NA, NA, NA, 803, "head"), # the parent, reference person + (901, 9, 30, NA, NA, NA, 901, "head"), + (902, 9, 17, NA, NA, NA, 902, "head"), # a minor parent 2, not 901's partner + (903, 9, 1, NA, 901, 902, 901, "dependent_child"), # follows parent 1 +] +REFERENCE = { + 1: 101, + 2: 201, + 3: 301, + 4: 401, + 5: 501, + 6: 601, + 7: 700, + 8: 803, + 9: 901, +} + + +def test_the_declaration_builds_the_stated_units() -> None: + person = pd.DataFrame( + { + "person_id": [row[0] for row in PEOPLE], + "person_household_id": [row[1] for row in PEOPLE], + "age": [row[2] for row in PEOPLE], + "partner_person_id": pd.array([row[3] for row in PEOPLE], dtype="Int64"), + "parent_1_person_id": pd.array([row[4] for row in PEOPLE], dtype="Int64"), + "parent_2_person_id": pd.array([row[5] for row in PEOPLE], dtype="Int64"), + } + ) + household = pd.DataFrame( + { + "household_id": list(REFERENCE), + "reference_person_id": list(REFERENCE.values()), + } + ) + # No usual_weekly_hours column: the rule declares no hours test. + (built,) = build_declared_units(person, household, _declaration()).values() + assert built.person_unit.name == f"person_{ENTITY}_id" + assert list(built.units.columns) == [ + f"{ENTITY}_id", + f"{ENTITY}_household_id", + f"{ENTITY}_head_person_id", + ] + assert built.person_unit.tolist() == [row[6] for row in PEOPLE] + assert built.person_role.tolist() == [row[7] for row in PEOPLE] + + +def _row_of(person: pd.DataFrame, pointer: pd.Series) -> np.ndarray: + """Each pointer's row position in ``person``, or -1 when it is absent.""" + rows = np.full(len(pointer), -1, dtype=np.int64) + present = pointer.notna().to_numpy() + ids = pd.Index(person["person_id"].to_numpy()) + rows[present] = ids.get_indexer(pointer[present].to_numpy(dtype=np.int64)) + return rows + + +# The shared generator draws each age evenly from 0 to 130 and ties it to no +# pointer, so ages are redrawn here around the limit: every run then holds +# dependent children aged 24 and adults aged 25. +AGES = st.sampled_from([0, 9, 16, 17, 18, 23, 24, 25, 26, 40, 70]) + + +@settings(max_examples=150, deadline=None, database=None, derandomize=True) +@given(tables=concept_frames(max_households=4, max_members=6), data=st.data()) +def test_the_declaration_decides_dependency_the_stated_way_on_any_frame( + tables, data +) -> None: + household = tables["household"] + person = tables["person"].copy() + count = len(person) + ages = data.draw(st.lists(AGES, min_size=count, max_size=count)) + person["age"] = np.array(ages, dtype=np.int64) + # The rule refuses nothing on membership, so every valid frame builds. + (built,) = build_declared_units(person, household, _declaration()).values() + unit = built.person_unit.to_numpy() + child = built.person_role.eq("dependent_child").to_numpy() + parent = _row_of(person, person["parent_1_person_id"]) + is_parent = person["person_id"].isin( + set(person["parent_1_person_id"].dropna()) + | set(person["parent_2_person_id"].dropna()) + ) + reference = pd.Series( + household["reference_person_id"].to_numpy(dtype=np.int64), + index=household["household_id"].to_numpy(), + ).reindex(person["person_household_id"].to_numpy()) + is_reference = person["person_id"].to_numpy() == reference.to_numpy() + # A dependent child is exactly a person aged 24 or under with no partner + # and no co-resident child, who has a co-resident parent or is not the + # household's reference person. No hours test and no parent age enter. + expected = ( + (person["age"].to_numpy() <= 24) + & person["partner_person_id"].isna().to_numpy() + & ~is_parent.to_numpy() + & ((parent >= 0) | ~is_reference) + ) + assert np.array_equal(child, expected) + # A dependent child sits with parent 1, or with the reference person when + # no parent lives in the household. + with_parent = child & (parent >= 0) + assert np.array_equal(unit[with_parent], unit[parent[with_parent]]) + without = child & (parent < 0) + reference_row = _row_of(person, pd.Series(reference.to_numpy(), dtype="Int64")) + assert np.array_equal(unit[without], unit[reference_row[without]]) diff --git a/packages/microcosm-build/tests/engine_free/shared/test_country_spec.py b/packages/microcosm-build/tests/engine_free/shared/test_country_spec.py index 675fdbfee7..1646c41306 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_country_spec.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_country_spec.py @@ -537,6 +537,7 @@ def test_loads_with_every_declared_resource(self, spec) -> None: "reference_profiles.json", "gates.json", "release_contract.json", + "unit_declarations.json", } assert set(spec.resource_hashes) == set(spec.resources) | { "country_package.json" diff --git a/packages/microcosm-build/tests/engine_free/shared/test_spec_engine_country_bundles.py b/packages/microcosm-build/tests/engine_free/shared/test_spec_engine_country_bundles.py index 7cbfd018f1..ccf3c6e6e8 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_spec_engine_country_bundles.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_spec_engine_country_bundles.py @@ -235,6 +235,7 @@ def test_be_generation_zero_views_still_come_from_the_country_spec_seam() -> Non "release_contract.json", "source_stages.json", "target_references.json", + "unit_declarations.json", } diff --git a/packages/microcosm-build/tests/golden/be_country_spec.json b/packages/microcosm-build/tests/golden/be_country_spec.json index b359c02b71..ad983fc72f 100644 --- a/packages/microcosm-build/tests/golden/be_country_spec.json +++ b/packages/microcosm-build/tests/golden/be_country_spec.json @@ -1,6 +1,6 @@ { "country": "be", - "fingerprint": "a72ec0eebcaf14cc2fe2830632fd7b7ca5cda3fefd3820995d2a0fa066d4f875", + "fingerprint": "2ff2ed3966b9375f85094a8b2219481bf2800e983f817faa4d83de78e1e67a7f", "gate_ids": [ "calibration_per_family_fit", "national_and_nuts1_admin_aggregates", @@ -29,10 +29,10 @@ "staging_repo": "policyengine/populace-be-staging" }, "resource_hashes": { - "axiom_input_closure.json": "bc40cbd6ae199d57b7d20548b2a052deb25ad9892a715dc90effd95d15012ef7", - "axiom_rules_bindings.json": "7b218789d46d64a743d5817fa7e79d1ac6213e290fe9646a5a323b24de8ed8ea", + "axiom_input_closure.json": "99b4438fd885dca88c50e5613d3b1076666a4339429c8d9373e1e9c396e6e3ea", + "axiom_rules_bindings.json": "352e3ba31151267d39a48e8b4629ade657acdb52eab391bc6437e7b72fb2db9d", "chronicle_feed.json": "291d9858510ec80baac4536bf4f821f85966f57f0a72be700889bbfeed0a4f4e", - "country_package.json": "c85c3e826d58e042429bc846e6e979a8e96f27265d6310a85904c70fe6248456", + "country_package.json": "4ac618f6e624f7128822db037d57dc882781b8b24429e0c482fcc1114bb4b276", "gates.json": "9704a0c86b324d4243365a320438b47a9d7d5a6af7ec2adfa1821ecb8d611f68", "geography_spine.json": "090b83a4fa511e691b8f1486bc4188e4170cf9d4a1239e7418d33d5020ceca50", "holdout_references.json": "d65875740c1be58a3233b25b65371267ea2a8b92e5b61b55f2353f4e63e64881", @@ -51,7 +51,8 @@ "spec/sources.yaml": "24ea9b8c9aac32175d1c75156af5549a05bb3f155fbb23968235f3ead2cbefda", "spec/spine.yaml": "981be4881954d7696fbabf1bc989f619577b6e5600262f1a9c20915461808d41", "spec/vintages.yaml": "1a10d5aedd24cdb2fc9544c7a0d444df0b06d4b089dcb769bf0a7de9218df696", - "target_references.json": "b2e9b6ccee9f72031c25815e50097f5cddb90226d29ac33d9568a3e5771ebcaf" + "target_references.json": "b2e9b6ccee9f72031c25815e50097f5cddb90226d29ac33d9568a3e5771ebcaf", + "unit_declarations.json": "6728d6c080390713571ea8730d2838450bb061caab72dabb2f62664e8600211e" }, "resources": [ "spec/bundle.yaml", @@ -75,7 +76,8 @@ "reference_profiles.json", "release_contract.json", "source_stages.json", - "target_references.json" + "target_references.json", + "unit_declarations.json" ], "stage_names": [ "load_populace_us_support_pool"