Repository navigation
engine: heph import add (STEP/mesh into imports/) - #36
Conversation
Admit a vendor STEP or scan into project imports/ without hand-copying. Optional --part seeds create_part with import_step or import_mesh + mesh_to_solid. Browser import stays deferred (INTERFACE.md §15.37). Closes #35. Co-authored-by: Vel <Code4me2@users.noreply.github.com>
write_part is on ProjectStore, not the raw opstore. Ingress path refusals now print [path_confinement] so the CLI names the same Stage 8A/12A reason the walk already raised. Co-authored-by: Vel <Code4me2@users.noreply.github.com>
Adversarial review (issue #35 / parent #14)Reviewed This is not a merge. Scope (does not trip the listed gates)
BLOCK: dest hardlink write-through (path escape)
Repro (this tree, just now): The planted-symlink case in That is the confinement claim (#35: path confinement, no escape; PR: "the destination is always a regular file — never a symlink — so a later import_step cannot escape through a link this verb planted"). The verb did not plant the link; it wrote through one that was already there. Same threat model as the symlink they already refuse. Fix that actually confines the write (any one is enough):
Add a hardlink case next to the existing symlink case. Until then the walk is not the Stage 8A/12A confinement it claims to be — that walk is a read. This is a write. Non-blocking notes (not the verdict)
BLOCK — |
A planted hardlink is a regular file; opening the dest with O_TRUNC wrote through the inode to a file outside the project. Write an exclusive temp under imports/ and rename onto the dest name so the outside link keeps its bytes. Symlink dests stay refused (O_NOFOLLOW). Co-authored-by: Vel <Code4me2@users.noreply.github.com>
Re-review: dest hardlink write-through only (
|
| Check | Result |
|---|---|
Dest opened with O_TRUNC |
Gone. Dest is never opened for write. Leaf is lstat (follow_symlinks=False) then os.replace. |
| Payload path | Exclusive temp under dest parent: O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW|O_CLOEXEC on .heph-import-{uuid}.tmp, write, then os.replace(tmp, leaf, src_dir_fd=fd, dst_dir_fd=fd). Same-dir renameat replaces the directory entry; the outside nlink keeps its bytes. |
| Planted dest hardlink test | test_add_does_not_write_through_a_planted_hardlink: imports/planted.step hardlinked to outside/secret.step, then heph import add … --name planted.step. Asserts outside bytes stay OUTSIDE-ORIGINAL-BYTES. On rc 0, dest has the payload and a different inode. |
| Symlink dest refused | test_add_refuses_traversal_and_symlink_escape still expects rc 1, dest remains a symlink, outside target not created. Walk stays O_NOFOLLOW; dest S_ISLNK is a named path_confinement refuse before replace. |
web/ / INTERFACE.md |
Unchanged. e81c56d touches only cli_import.py + test_cli_import.py. |
os.replace on a dest hardlink unlinks that name from the shared inode. It does not truncate it. A dest symlink is refused, not followed; even a TOCTOU swap-to-symlink would replace the link itself on Linux, not write through it.
The earlier BLOCK is closed.
MERGE — dest hardlink write-through is gone: exclusive temp under imports/ then rename, outside bytes unchanged, symlink dest still refused.
Closes #35 (parent #14). Engine/CLI only — no
web/, no #29 scan-to-part, no second kernel, no surface reconstruction.What this is
Kernel import already exists (
import_step,import_mesh/import_point_cloud). The hole was project ingress: an operator could not admit a vendor STEP or scan intoimports/without hand-copying.heph reference addis the document counterpart; this is the geometry one.INTERFACE.md§15.37 is unchanged: browser / viewport import stays deferred. One sentence indocs/cli.mdrecords that.Verbs
heph import add FILEcopies into projectimports/(path confinement,O_NOFOLLOW, original untouched).--jsonemits{name, kind: step|mesh|points, sha256, path, units?}..step/.stp, AP203/AP214): no--units. STL/PLY/OBJ/OFF/XYZ require--units {mm,cm,m,in}(never inferred). Unknown suffix is a named refusal.--part NAMEseedsparts/<name>.pythroughcreate_part(refuse if exists, no force):part.geometry = import_step("copied-name")import_mesh(..., units=...)thenmesh_to_solidwith the declared unitheph import listlistsimports/the wayheph reference listlists references.Confinement
O_NOFOLLOW; a planted dest symlink is refused.O_TRUNC. Payload goes to an exclusive temp inode underimports/, thenrenameonto the dest name, so a planted hardlink cannot write through to a file outside the project.Tests
core/tests/test_cli_import.py(13 passed): happy STEP (exportedBox) + mesh, missing file, traversal/symlink, planted dest hardlink (outside bytes unchanged), mesh without units, existing part name, suffix/units/--partseed contracts.