Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
10f0583
AutoStory: story types and engine, split out of #122
dayfine Nov 10, 2026
5b974f0
AutoStory: story data types in Types/, executor as a data-free interf…
dayfine Nov 10, 2026
1b74c82
AutoStory: structured step args next to a plain variant name
dayfine Nov 10, 2026
dd9529b
AutoStory: shared story range options and story log lines
dayfine Nov 10, 2026
babbf85
Merge remote-tracking branch 'origin/nav/story-engine' into nav/story…
dayfine Nov 10, 2026
48c10b7
StoryRangeOptions: let a program unlock the end while running
dayfine Nov 10, 2026
c766e87
AutoStory tests: register the story engine suites through one call
dayfine Nov 10, 2026
d3e856e
Merge nav/shared (one-line route plan) into nav/story-engine
dayfine Nov 10, 2026
093d1ab
Merge branch 'review312/nav-shared' into nav/story-engine
dayfine Nov 10, 2026
a940ce0
AutoStory: move the JSON codecs to Data/, StorySteps to StoryStepExec…
dayfine Nov 10, 2026
e8833b3
AutoStory: review fixes to the story engine's API (#312)
dayfine Nov 10, 2026
31ddeae
AutoStory: steps carry an action and typed args (#312 review)
dayfine Nov 10, 2026
8dad6da
AutoStory: test steps get their built-in action's fallbacks, as loadi…
dayfine Nov 10, 2026
8fd27c7
Merge nav/shared (#114) into nav/story-engine: StoryLog, StoryRangeOp…
dayfine Nov 10, 2026
c51e57f
AutoStory: built-in actions in Pokemon_BuiltinStoryActions, clear of …
dayfine Nov 10, 2026
20c4961
Merge branch 'nav/shared' into nav/story-engine
dayfine Nov 10, 2026
6a1e81a
AutoStory: save modes and a postcondition check
dayfine Nov 10, 2026
8e82401
Merge nav/shared (run report / range options split) into nav/story-en…
dayfine Nov 10, 2026
f3e190d
Merge nav/story-engine (run report / range options split) into autost…
dayfine Nov 10, 2026
f2962a9
Merge branch 'nav/shared' into nav/story-engine
dayfine Nov 10, 2026
af19559
AutoStory: story step suites in their own test header
dayfine Nov 10, 2026
50adad1
Merge branch 'nav/story-engine' into autostory/save-policy
dayfine Nov 10, 2026
e1f068b
AutoStory save policy: output parameters last, std::format
dayfine Nov 10, 2026
aa4f2bd
AutoStory: story steps take inputs first; std::format; per-suite test…
dayfine Nov 10, 2026
ee30e9f
Merge nav/story-engine into autostory/save-policy
dayfine Nov 10, 2026
2428141
Merge nav/shared into nav/story-engine
dayfine Nov 10, 2026
fff3615
Merge nav/story-engine into autostory/save-policy
dayfine Nov 10, 2026
264b725
Merge remote-tracking branch 'origin/nav/shared' into HEAD
dayfine Nov 11, 2026
d535358
Merge nav/story-engine into autostory/save-policy
dayfine Nov 11, 2026
1420085
Merge origin/nav/shared into nav/story-engine
dayfine Nov 12, 2026
27c91d3
Merge origin/nav/story-engine into autostory/save-policy
dayfine Nov 12, 2026
41905b9
Merge branch 'nav/shared' into nav/story-engine
dayfine Nov 12, 2026
d898f8f
Merge origin/nav/shared into nav/story-engine
dayfine Nov 12, 2026
b7bd1a6
Merge origin/nav/story-engine into autostory/save-policy
dayfine Nov 12, 2026
f3e65fb
Merge autostory/save-policy (#329) into nav/story-engine
dayfine Nov 13, 2026
456f87a
Merge origin/nav/shared into nav/story-engine
dayfine Nov 13, 2026
62667cb
Merge branch 'nav/shared' into nav/story-engine
dayfine Nov 13, 2026
630f19b
Merge branch 'nav/shared' into nav/story-engine
dayfine Nov 13, 2026
4f2339d
Merge remote-tracking branch 'origin/nav/shared' into HEAD
dayfine Nov 13, 2026
a402d33
Merge origin/nav/shared into nav/story-engine: #45 review fixes
dayfine Nov 13, 2026
895fe4f
Merge origin/nav/shared into nav/story-engine: #45 review fixes
dayfine Nov 13, 2026
ba5efca
Merge origin/nav/shared into nav/story-engine: shared checkpoint retr…
dayfine Nov 13, 2026
a8546e7
Merge origin/nav/shared into nav/story-engine
dayfine Nov 13, 2026
fb669bf
Merge origin/nav/shared into nav/story-engine: StoryRunCounts moves t…
dayfine Nov 13, 2026
9b28861
Merge nav/shared into nav/story-engine
dayfine Nov 14, 2026
3438d7a
Story segments: the not-saving lines through checkpoint_log_line
dayfine Nov 14, 2026
dc7afd6
Merge nav/shared into nav/story-engine: add_checkpoint_prefix (#45)
dayfine Nov 14, 2026
07eae1d
Merge nav/shared into nav/story-engine
dayfine Nov 14, 2026
e4ce5af
Merge nav/shared into nav/story-engine
dayfine Nov 14, 2026
0957678
Story data codec: drop the stale PokemonSimulation native conformance…
dayfine Nov 14, 2026
68e4ecf
AutoStory: a single step after the last target leaves the end pose un…
dayfine Nov 14, 2026
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
30 changes: 30 additions & 0 deletions .github/workflows/story-data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Story data codec
on:
pull_request:
workflow_dispatch:
jobs:
native-codec:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@v7
with:
repository: dayfine/PokemonSimulation
# Synthetic contract cases, not an approved map/resource pin.
ref: 866613fa03e5c4a5eb7e57c91b59fafb44fc7ee3
path: publisher
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Check the Python reader against the same cases
working-directory: publisher
env:
PYTHONPATH: src
run: python -m unittest pokesim.story.test_checkpoint_wire
- run: cmake -S devtools/story-data-tests -B build-story-data -DCMAKE_BUILD_TYPE=Debug
- run: cmake --build build-story-data --config Debug -j4
- run: ctest --test-dir build-story-data -C Debug --output-on-failure
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Shared Authored Checkpoint JSON
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <utility>
#include "Common/Cpp/Exceptions.h"
#include "Pokemon_StoryStepJson.h"
#include "Pokemon_AuthoredCheckpointJson.h"

namespace PokemonAutomation{
namespace Pokemon{


void validate_json_fields(
const JsonObject& object, std::initializer_list<std::string_view> fields, std::string_view source
){
if (object.size() != fields.size()){
throw ParseException(std::format("{}: missing or extra authored checkpoint fields.", source));
}
for (std::string_view field : fields){
object.get_value_throw(std::string(field), std::string(source));
}
}

StoryCheckpoint read_authored_checkpoint(
const JsonValue& value, std::string_view game, std::string_view source,
const ExecutionReader& read_execution, std::span<const StoryActionSpec> actions
){
const JsonObject& root = value.to_object_throw(std::string(source));
validate_json_fields(root, {"format", "game", "checkpoint", "execution"}, source);
if (game.empty() || root.get_string_throw("format") != "pokesim-authored-checkpoint/1"
|| root.get_string_throw("game") != game
){
throw ParseException(std::format("{}: unsupported authored checkpoint format/game.", source));
}
StoryCheckpoint checkpoint = read_story_checkpoint(root.get_value_throw("checkpoint"), source, actions);
read_execution(root.get_object_throw("execution", std::string(source)), source);
return checkpoint;
}

JsonValue authored_checkpoint_json(const StoryCheckpoint& checkpoint, std::string_view game, JsonObject execution){
if (game.empty()){
throw ParseException("Authored checkpoint game must not be empty.");
}
JsonObject result;
result["format"] = "pokesim-authored-checkpoint/1";
result["game"] = std::string(game);
result["checkpoint"] = story_checkpoint_json(checkpoint);
result["execution"] = std::move(execution);
return result;
}

StoryCheckpoint load_authored_checkpoint(
std::span<const EmbeddedJsonFile> files, std::string_view file, std::string_view game,
const ExecutionReader& read_execution, std::span<const StoryActionSpec> actions
){
for (const auto& [name, text] : files){
if (name == file){
return read_authored_checkpoint(parse_json(text), game, file, read_execution, actions);
}
}
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("Authored checkpoint is not embedded: {}", file));
}



} // namespace Pokemon
} // namespace PokemonAutomation
Comment thread
dayfine marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Shared Authored Checkpoint JSON

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this simply parsing?

AuthoredCheckpoint - I wonder if we need to keep both at the same time

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it only parses and encodes; the header now says so (e8833b3). AuthoredCheckpoint is the shared StoryCheckpoint plus the game's execution object, still raw JSON. We could drop the wrapper by having read_authored_checkpoint() return the checkpoint and pass execution to a game callback, or by letting each game parse its own envelope. Do you want either?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main feedback is to keep IO and in-game logic separate

so parsing should be done in one layer, then everything else no longer need JSON, is that fair / possible?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 31ddeae: read_story_step() parses args against the action's spec and fills fallbacks; the authored envelope hands execution to the game's reader and AuthoredCheckpoint (with its JsonObject) is gone.

*
* From: https://github.com/PokemonAutomation/
*
* Reading and writing an authored checkpoint file: the shared
* StoryCheckpoint (Pokemon_StoryStepJson.h) in an envelope that names the
* game, plus the game's own execution object, which the game parses into
* its own type through a reader it passes in. Only parsing and encoding:
* nothing here binds or runs a step, and nothing read keeps JSON.
*
*/

#ifndef PokemonAutomation_AuthoredCheckpointJson_H
#define PokemonAutomation_AuthoredCheckpointJson_H

#include <functional>
#include <initializer_list>
#include <span>
#include <string>
#include <string_view>
#include <utility>
#include "Common/Cpp/Json/JsonObject.h"
#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h"
#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h"

namespace PokemonAutomation{
namespace Pokemon{


// The game's reader of an envelope's execution object: it parses the
// object into the game's own type and throws ParseException when it is
// malformed.
using ExecutionReader = std::function<void(const JsonObject& execution, std::string_view source)>;

// Require exactly these fields, including fields whose value is null/zero/false.
// Missing/unknown fields throw ParseException with the document source.
void validate_json_fields(
const JsonObject& object, std::initializer_list<std::string_view> fields, std::string_view source
);

// The checkpoint of `game`'s strict authored envelope, its steps read
// against `actions` (read_story_checkpoint()); its execution object goes
// to `read_execution`.
StoryCheckpoint read_authored_checkpoint(
const JsonValue& value, std::string_view game, std::string_view source,
const ExecutionReader& read_execution,
std::span<const StoryActionSpec> actions = builtin_story_actions()
);

// Encode the authored envelope; execution is supplied by the game adapter.
// This does not encode game bookkeeping or the legacy native-export envelope.
JsonValue authored_checkpoint_json(const StoryCheckpoint& checkpoint, std::string_view game, JsonObject execution);

// A JSON file built into the program: its name without ".json", and its
// text.
using EmbeddedJsonFile = std::pair<std::string, std::string>;

// Find embedded file `file` among `files` and parse it as
// read_authored_checkpoint() does. Missing resources throw
// InternalProgramError; malformed documents throw ParseException.
StoryCheckpoint load_authored_checkpoint(
std::span<const EmbeddedJsonFile> files, std::string_view file, std::string_view game,
const ExecutionReader& read_execution,
std::span<const StoryActionSpec> actions = builtin_story_actions()
);



} // namespace Pokemon
} // namespace PokemonAutomation

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/* Shared Authored Checkpoint JSON Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#include <format>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include "Common/Cpp/Exceptions.h"
#include "Pokemon_AuthoredCheckpointJson.h"
#include "Pokemon_StoryStepJson.h"
#ifndef PA_STORY_DATA_STANDALONE
#include "Pokemon_AuthoredCheckpointJson_Tests.h"
#endif

namespace PokemonAutomation{
namespace Pokemon{


namespace{


// Documents intentionally contain no game headers or native bookkeeping.
const std::string FRLG = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{"id":"00.05","title":"Parcel","events":[{"id":"first","kind":"talk"},{"id":"second","kind":"scene"}]},"execution":{"menu":"before_pokedex"}})";
const std::string BDSP = R"({"format":"pokesim-authored-checkpoint/1","game":"bdsp","checkpoint":{"id":"01.03","title":"Mine","events":[{"id":"roark","kind":"talk"}]},"execution":{"on_failure":"reload_and_retry","saves_in":"Oreburgh City"}})";

// How a case fails, if it does.
enum class Failure{
NONE,
PARSE,
MISSING_RESOURCE,
};

struct AuthoredInput{
std::string name;
std::string json;
std::string game = "frlg";
bool resource = false;
std::string file = "plan";
};

struct AuthoredExpectation{
std::string checkpoint = "00.05";
std::string execution = R"({"menu":"before_pokedex"})";
std::vector<std::string> events = {"first", "second"};
Failure failure = Failure::NONE;
};

struct AuthoredCase{
AuthoredInput input;
AuthoredExpectation expectation;
};

const AuthoredCase CASES[] = {
{.input = {.name = "FRLG envelope", .json = FRLG}, .expectation = {}},
{.input = {.name = "BDSP embedded resource", .json = BDSP, .game = "bdsp", .resource = true}, .expectation = {
.checkpoint = "01.03", .execution = R"({"on_failure":"reload_and_retry","saves_in":"Oreburgh City"})", .events = {"roark"}}},
{.input = {.name = "FRLG embedded resource", .json = FRLG, .resource = true}, .expectation = {}},
{.input = {.name = "wrong game", .json = BDSP}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "empty expected game", .json = FRLG, .game = ""}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "missing resource", .json = FRLG, .resource = true, .file = "absent"}, .expectation = {.failure = Failure::MISSING_RESOURCE}},
{.input = {.name = "invalid embedded JSON", .json = "{", .resource = true}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "wrong format", .json = R"({"format":"future","game":"frlg","checkpoint":{},"execution":{}})"}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "missing execution", .json = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{}})"}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "same count wrong field", .json = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{},"extra":{}})"}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "extra envelope field", .json = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{},"execution":{},"extra":0})"}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "execution must be object", .json = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{"id":"x","title":"X","events":[]},"execution":false})"}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "invalid common action", .json = R"({"format":"pokesim-authored-checkpoint/1","game":"frlg","checkpoint":{"id":"x","title":"X","events":[{"id":"bad","kind":"magic"}]},"execution":{}})"}, .expectation = {.failure = Failure::PARSE}},
{.input = {.name = "execution stays game owned", .json = R"({"format":"pokesim-authored-checkpoint/1","game":"future","checkpoint":{"id":"x","title":"X","events":[]},"execution":{"zero":0,"false":false,"null":null}})", .game = "future"}, .expectation = {
.checkpoint = "x", .execution = R"({"zero":0,"false":false,"null":null})", .events = {}}},
};


// What a test reads: the checkpoint, and the execution object its reader
// kept.
struct Loaded{
StoryCheckpoint checkpoint;
JsonObject execution;
};

// A reader that keeps the execution object in `kept`.
ExecutionReader keep_execution(JsonObject& kept){
return [&kept](const JsonObject& execution, std::string_view){
kept = execution.clone();
};
}

// "" when `actual` is what `test` expects and survives a write and a
// read, else what was expected and what was read.
std::string check_loaded(const Loaded& actual, const AuthoredCase& test){
if (test.expectation.failure != Failure::NONE){
return "Expected rejection, read accepted authored checkpoint.";
}
if (actual.checkpoint.id != test.expectation.checkpoint){
return std::format("Expected checkpoint {}, read {}", test.expectation.checkpoint, actual.checkpoint.id);
}
if (!(JsonValue(actual.execution.clone()) == parse_json(test.expectation.execution))){
return std::format("Expected execution {}, read {}", test.expectation.execution, actual.execution.dump());
}
std::vector<std::string> events;
for (const StoryStep& step : actual.checkpoint.steps){
events.push_back(step.name);
}
if (events != test.expectation.events){
return "Expected authored event IDs in their original order.";
}
const JsonValue encoded = authored_checkpoint_json(actual.checkpoint, test.input.game, actual.execution.clone());
Loaded reread;
reread.checkpoint = read_authored_checkpoint(encoded, test.input.game, test.input.name, keep_execution(reread.execution));
if (!(story_checkpoint_json(actual.checkpoint) == story_checkpoint_json(reread.checkpoint)) || actual.execution != reread.execution){
return "Expected checkpoint and execution to survive the shared writer/reader round trip.";
}
return "";
}

// "" when `test` reads or fails as expected.
std::string check_case(const AuthoredCase& test){
try{
const std::vector<std::pair<std::string, std::string>> files = {{"plan", test.input.json}};
Loaded actual;
actual.checkpoint = test.input.resource
? load_authored_checkpoint(files, test.input.file, test.input.game, keep_execution(actual.execution))
: read_authored_checkpoint(parse_json(test.input.json), test.input.game, test.input.name, keep_execution(actual.execution));
return check_loaded(actual, test);
}catch (const ParseException& error){
return test.expectation.failure == Failure::PARSE ? "" : std::format("Unexpected parse failure: {}", error.message());
}catch (const InternalProgramError& error){
return test.expectation.failure == Failure::MISSING_RESOURCE ? "" : std::format("Unexpected resource failure: {}", error.message());
}
}


#ifndef PA_STORY_DATA_STANDALONE

class AuthoredJsonTest : public UnitTest{

Check failure on line 138 in SerialPrograms/Source/Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson_Tests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

test-case: construct each UnitTest from one case struct with name, input and expectation fields (input and expectation structs, the name outside the input); register a named table of designated cases in a range-for
public:
explicit AuthoredJsonTest(AuthoredCase test)
: UnitTest(std::format("Pokemon::AuthoredCheckpointJson - {}", test.input.name))
, m_case(std::move(test))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const std::string error = check_case(m_case);
return error.empty() ? UnitTestResult(true) : UnitTestResult(error);
}

private:
AuthoredCase m_case;
};

#endif


} // namespace


#ifndef PA_STORY_DATA_STANDALONE

void add_tests_AuthoredCheckpointJson(UnitTestDatabase& database){
for (const AuthoredCase& test : CASES){
database.add<AuthoredJsonTest>(test);
}
}

#endif



} // namespace Pokemon
} // namespace PokemonAutomation


#ifdef PA_STORY_DATA_STANDALONE

int main(){
int failed = 0;
for (const auto& test : PokemonAutomation::Pokemon::CASES){
const std::string error = PokemonAutomation::Pokemon::check_case(test);
std::cout << test.input.name << ": " << (error.empty() ? "PASS" : error) << '\n';
failed += !error.empty();
}
return failed != 0;
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Authored Checkpoint JSON Tests
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_Pokemon_AuthoredCheckpointJson_Tests_H
#define PokemonAutomation_Pokemon_AuthoredCheckpointJson_Tests_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace Pokemon{


// Registers unit tests for the shared authored envelope, game identity and embedded-resource loading.
void add_tests_AuthoredCheckpointJson(UnitTestDatabase& database);



} // namespace Pokemon
} // namespace PokemonAutomation
#endif
Loading
Loading