Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions kits/profile-dev-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,32 @@ never ratify or write inventory versions.
```text
beddel run -i ... workflows/verify-and-fix-story.yaml
```

## Delivery: integrate stage

`integrate-story` takes `repo_path`, `story_key`, `spec_path`, `branch`,
`base_branch`, `remote`, `change_id`, `parent_path`, `parent_branch` and an
optional `status_path`. It reads the recorded Approval and the latest
consistent Report, validates the feature branch and parent gitlink, then runs
fetch, land, push, pull request, checks, merge and refetch. The pull request
contains references only: the story key, spec path, Change id and approved
revision.

The stage refuses before host work for an absent or invalid Approval, a pending
Report, unapproved commits, invalid inputs, a bad parent or a malformed status
file. It confirms the merge from Git after a successful fetch and pins the host
merge to the checked branch tip. A rerun reuses a merged tip and an existing
parent pointer instead of repeating those actions.

It records one `integrate` outcome at the Change-repository boundary and one at
the parent boundary. Common reasons include `approval.absent`,
`verdict.has_pendency`, `revision.unapproved`, `merge.confirmed`,
`merge.reused`, `pointer.unpublished`, `integrate.complete` and
`fetch.failed`. The status mapping is edited only after a successful parent
fetch confirms the pointer on the parent remote. The workflow never approves,
verifies or pushes the parent; the owner commits the status file and pushes
the parent.

```text
beddel run -i ... workflows/integrate-story.yaml
```
21 changes: 21 additions & 0 deletions kits/profile-dev-kit/kit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ tools:
target: "beddel_profile_dev.tools.fix:profile_fix_settle"
description: "Validate and commit one verification fix round"
category: profile
- name: profile_integrate_prepare
target: "beddel_profile_dev.tools.integrate:profile_integrate_prepare"
description: "Prepare one approved Change for integration"
category: profile
- name: profile_integrate_reconcile
target: "beddel_profile_dev.tools.integrate:profile_integrate_reconcile"
description: "Reconcile remote integration state"
category: profile
- name: profile_integrate_settle
target: "beddel_profile_dev.tools.integrate:profile_integrate_settle"
description: "Settle the parent integration boundary"
category: profile

workflows:
- name: verify-change
Expand Down Expand Up @@ -160,6 +172,9 @@ workflows:
- name: plan-story
path: workflows/plan-story.yaml
description: Plans one selected story into one implementation spec through a Coding agent; never implements, verifies or commits.
- name: integrate-story
path: workflows/integrate-story.yaml
description: Integrates one approved Change through the repository host and records the parent boundary; never approves, verifies or pushes the parent.

targets:
python:
Expand Down Expand Up @@ -213,6 +228,12 @@ targets:
target: "beddel_profile_dev.tools.fix:profile_fix_reconcile"
- name: profile_fix_settle
target: "beddel_profile_dev.tools.fix:profile_fix_settle"
- name: profile_integrate_prepare
target: "beddel_profile_dev.tools.integrate:profile_integrate_prepare"
- name: profile_integrate_reconcile
target: "beddel_profile_dev.tools.integrate:profile_integrate_reconcile"
- name: profile_integrate_settle
target: "beddel_profile_dev.tools.integrate:profile_integrate_settle"
typescript:
status: unavailable
unavailable_reason: >
Expand Down
77 changes: 77 additions & 0 deletions kits/profile-dev-kit/python/beddel_profile_dev/integrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""Pure helpers for the integration stage."""

from __future__ import annotations

import re

from beddel_profile_dev.implement import STORY_TRAILER

APPROVALS_DIR = ".beddel-profile/approvals/"
REMOTE = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,63}")
STATUS_VALUE = re.compile(r"[a-z][a-z0-9-]{0,31}")
MAX_STATUS_BYTES = 1048576
MERGE_TRAILER = "Integrate-Merge"


def approved_only(paths: list[str] | tuple[str, ...] | set[str]) -> bool:
"""Return whether every changed path belongs to the approval directory."""
return all(path.startswith(APPROVALS_DIR) for path in paths)


def _matching(data: bytes, key: str) -> list[tuple[int, str, str]]:
try:
text = data.decode("utf-8")
except UnicodeDecodeError:
return []
pattern = re.compile(rf"^[ \t]*{re.escape(key)}:[ \t]*[^\s#]*[ \t]*(#.*)?$")
matches: list[tuple[int, str, str]] = []
for index, raw in enumerate(text.splitlines(keepends=True)):
line = raw.rstrip("\r\n")
match = pattern.fullmatch(line)
if match is not None:
value_match = re.search(r":([ \t]*)([^\s#]+)", line)
if value_match is not None:
matches.append((index, line, value_match.group(2)))
return matches


def status_lines(data: bytes, key: str) -> list[int]:
"""Return line indexes containing exactly one valid status mapping."""
return [index for index, _line, _value in _matching(data, key)]


def status_value(data: bytes, key: str) -> str | None:
"""Return the status value when the requested key occurs exactly once."""
matches = _matching(data, key)
return matches[0][2] if len(matches) == 1 else None


def set_status(data: bytes, key: str, value: str) -> bytes | None:
"""Replace one status token without changing any other file bytes."""
matches = _matching(data, key)
if len(matches) != 1:
return None
try:
text = data.decode("utf-8")
except UnicodeDecodeError:
return None
lines = text.splitlines(keepends=True)
index, line, _old = matches[0]
match = re.match(
rf"^(?P<prefix>[ \t]*{re.escape(key)}:[ \t]*)[^\s#]+(?P<suffix>.*)$", line
)
if match is None or not STATUS_VALUE.fullmatch(value):
return None
lines[index] = (
f"{match.group('prefix')}{value}{match.group('suffix')}"
+ lines[index][len(line) :]
)
return "".join(lines).encode("utf-8")


def pointer_message(story_key: str, sub_path: str, merge: str) -> tuple[str, str]:
"""Return the pointer commit subject and its identity trailers."""
return (
f"chore: update {sub_path} pointer",
f"{STORY_TRAILER}: {story_key}\n{MERGE_TRAILER}: {merge}",
)
Loading
Loading