requirements.refactor.moved_function
Requirements index · View definition
Example
fn[load]moves unchanged fromsrc/config.rstosrc/config/load.rs, and nothing else changes.habeas refactor --map 'src/config.rs#fn[load]=src/config/load.rs#fn[load]'rewrites the outline inputs that read it, recomputes the reference-set digests of the requirements it implements, rewrites`src/config.rs#fn[load]`in their rationales, and validation then passes without calling a model.![]()
![]()
![]()
Rationale
The example has a {test} reference from tests/refactor.rs#fn[a_moved_function_keeps_its_evidence_current]. I read that test and its helpers (project, config_source, author, write_evidence, move_load, refactor, errors). I did not read the bodies of errors and move_load in full, so for those I relied on their names, doc comments and visible lines.
Setup. The fixture project has src/config.rs with fn load carrying {impl} and {test} references to rules.load. author writes current evidence for rules.load. That evidence has outline inputs on src/config.rs fn[load] and fn[verify], a reference-set digest from habeas::reference_set_digest_for, and a rationale containing the code span `src/config.rs#fn[load]`. move_load moves load unchanged into src/config/load.rs (LOAD_ALONE) and removes it from src/config.rs.
Assertions on each expected outcome:
- Starting state. Validation is clean before the move and reports a stale
fn[load]error after it. - Command.
habeas refactor --map 'src/config.rs#fn[load]=src/config/load.rs#fn[load]'succeeds. - Outline inputs.
record["inputs"][1]["file"]issrc/config/load.rs. - Rationale. The rationale becomes
`src/config/load.rs#fn[load]` loads it…. The other mention,src/config.rsforverify, is left alone and listed for review. - Reference-set digest. The
{impl}reference moved files, so the reference set changed.errors(root)is empty after the refactor, so the recomputed digest is valid. - Passes without a model. Validation is the deterministic
validate_repositorycall, and it passes. - Only affected records change. The report says
Changed 1 recordsand lists onlyevidence/rules.load.json.rules.check, which reads no moved node, is byte-identical. - Idempotence. A second run reports
Changed 0 records.
The cited requirements are context only, so I did not reassess them. The test covers the example’s scenario and each stated outcome.
Inputs
Tests
Input 6: outline tests/refactor.rs fn[a_moved_function_keeps_its_evidence_current]
- File:
tests/refactor.rs - Selector:
fn[a_moved_function_keeps_its_evidence_current] - Kind:
fn tests/refactor.rs:171–241
// {test}`requirements.refactor.moved_function`
// {test}`requirements.refactor.command`
// {test}`requirements.refactor.outline_inputs`
// {test}`requirements.refactor.reference_digest`
// {test}`requirements.refactor.rationale.addresses`
// {test}`requirements.refactor.rationale.untouched`
// {test}`requirements.refactor.record_fields`
// {test}`requirements.refactor.equivalence`
// {test}`requirements.refactor.whole_record`
// {test}`requirements.refactor.mappings`
#[test]
fn a_moved_function_keeps_its_evidence_current() {
let temp = project();
let root = temp.path();
author(root);
assert_eq!(errors(root), Vec::<String>::new());
move_load(root, "");
let stale = errors(root);
assert!(
stale.iter().any(|error| error.contains("fn[load]")),
"{stale:#?}"
);
let unaffected = fs::read(root.join("evidence/rules.check.json")).unwrap();
let output = refactor(
root,
&[
"--map",
"src/config.rs#fn[load]=src/config/load.rs#fn[load]",
],
);
assert!(output.status.success(), "{output:?}");
let report = stdout(&output);
assert!(
report.contains("Changed 1 records:\n- evidence/rules.load.json\n"),
"{report}"
);
// The other mention of the old file is listed for review.
assert!(
report.contains("review the rationale's `src/config.rs`"),
"{report}"
);
// `rules.check` reads no moved node, so it is unaffected and unchanged.
assert!(!report.contains("rules.check"), "{report}");
assert_eq!(
fs::read(root.join("evidence/rules.check.json")).unwrap(),
unaffected
);
assert_eq!(errors(root), Vec::<String>::new());
let record: Value =
serde_json::from_str(&fs::read_to_string(root.join("evidence/rules.load.json")).unwrap())
.unwrap();
assert_eq!(record["inputs"][1]["file"], "src/config/load.rs");
assert_eq!(
record["rationale"],
"`src/config/load.rs#fn[load]` loads it, as `rules.load` asks; `verify` tests it in `src/config.rs`."
);
// Running it again changes nothing.
let again = refactor(
root,
&[
"--map",
"src/config.rs#fn[load]=src/config/load.rs#fn[load]",
],
);
assert!(
stdout(&again).contains("Changed 0 records:"),
"{}",
stdout(&again)
);
}
Referenced definitions
Input 2: requirements selection requirements.refactor.outline_inputs
requirements.refactor.outline_inputs:md/requirements/refactor.md:65–71
:::{req} outline_inputs
An outline input MUST be rewritten only if the mapped node exists and its
structural hash, computed under
{cite}`requirements.references.structural_hash` over the
{term}`requirements.refactor.mapped_back` text of the node, equals the recorded
hash.
:::
Input 3: requirements selection requirements.refactor.reference_digest
requirements.refactor.reference_digest:md/requirements/refactor.md:87–91
:::{req} reference_digest
A record's `references` digest MUST be rewritten only if the
{term}`requirements.refactor.mapped_back` current reference set of its subject,
under {cite}`requirements.ci.reference_set`, has the recorded digest.
:::
Input 4: requirements selection requirements.refactor.rationale.addresses
requirements.refactor.rationale.addresses:md/requirements/refactor.md:144–148
:::{req} rationale.addresses
In the rationale of each changed record, `habeas refactor` MUST rewrite each
code span that is exactly `<file>#<selector>` for a mapped node, or for a node
in a mapped file, to the node's new address.
:::
Input 5: requirements selection requirements.refactor.equivalence
requirements.refactor.equivalence:md/requirements/refactor.md:103–106
:::{req} equivalence
After `habeas refactor` succeeds, each record it changed MUST pass or fail
validation exactly as it did before the move.
:::
Input 7: definition requirements.refactor.mapped_back
requirements.refactor.mapped_back:md/requirements/refactor.md:58–63
:::{definition} mapped_back
:phrase: mapped-back
The *mapped-back* form of current text or a current address is the text or
address with each new side of the mappings replaced by its old side.
:::
Other sources
Input 1: requirements selection requirements.refactor.moved_function
requirements.refactor.moved_function:md/requirements/refactor.md:161–171
:::{example} moved_function
`fn[load]` moves unchanged from `src/config.rs` to `src/config/load.rs`, and
nothing else changes. `habeas refactor --map 'src/config.rs#fn[load]=src/config/load.rs#fn[load]'`
rewrites the outline inputs that read it, recomputes the reference-set digests
of the requirements it implements, rewrites `` `src/config.rs#fn[load]` `` in
their rationales, and validation then passes without calling a model.
{cite}`requirements.refactor.outline_inputs`
{cite}`requirements.refactor.reference_digest`
{cite}`requirements.refactor.rationale.addresses`
{cite}`requirements.refactor.equivalence`
:::