<?php
require 'examples/boot.php';
require_once dirname(__DIR__).'/Support.php';
use Cognesy\Tell\Tell;
use Cognesy\Tell\TellRequest;
$project = TellHarnessExample::project();
try {
$tell = Tell::testing($project, 'deterministic workspace result');
$workspace = $tell->workspace();
$workspace->initialize();
// Give main a durable head, then fork a review branch from it.
$tell->run(TellRequest::prompt('Record the release baseline.')->durable());
$branches = $workspace->branches();
$review = $branches->create('release-review');
$branches->checkout($review->name);
$result = $tell->run(
TellRequest::prompt('Review the release candidate.')->durable(),
);
echo 'Published on branch: '.$result->branch()."\n";
// A branch handle reads that named branch regardless of later checkout.
// Pinning captures an immutable head that remains readable after ref moves.
$reviewHandle = $workspace->branch('release-review');
$frozen = $reviewHandle->pin();
// Preserve a named recovery point before moving release-review back.
$recovery = $branches->create('release-review-recovery', from: 'release-review');
$reset = $branches->reset('release-review', steps: 1);
echo 'Recovery branch: '.$recovery->name."\n";
echo 'Reset '.($reset->changed ? 'completed' : 'did not change the head')."\n";
echo 'Review turns after reset: '.count($reviewHandle->history()->turns)."\n";
echo 'Frozen turns: '.count($frozen->history()->turns)."\n";
assert($result->isCompleted(), 'Expected durable branch work to complete.');
assert($reset->changed, 'Expected the branch reset to move one ancestor back.');
assert(count($reviewHandle->history()->turns) === 1);
assert(count($frozen->history()->turns) === 2);
} finally {
TellHarnessExample::remove($project);
}