Skip to content

Philosophy docs and code fixes - #434

Merged
ocots merged 8 commits into
mainfrom
philosophy-docs-and-code-fixes
Jun 6, 2026
Merged

Philosophy docs and code fixes#434
ocots merged 8 commits into
mainfrom
philosophy-docs-and-code-fixes

Conversation

@ocots

@ocots ocots commented Jun 5, 2026

Copy link
Copy Markdown
Member

Updated Summary

This PR adds philosophy documentation and applies code standards to align with the control-toolbox ecosystem conventions.

Documentation Added

  • AGENTS.md: Agent navigation guide for CTBase.jl
  • CLAUDE.md: Claude project context with essential rules
  • dev/philosophy/: Code philosophy documentation
    • modules.md: Submodule organization, imports/qualification, DAG, exports
    • types-traits-interfaces.md: Types vs traits, interfaces/contracts, SOLID/DRY/YAGNI, type stability
    • exceptions.md: The 7 exceptions and the choice rule
    • docstrings.md: Docstring templates, cross-references, example safety
    • testing.md: Categories, fakes/stubs, module + callable function template
    • documentation.md: API generation, guides, draft workflow
  • dev/planning.md: Implementation plan template
  • dev/RULES.md: Operational rules (MCP, doc build, git, output capture)

These documents are adapted from CTFlows to be generic for all packages in the ecosystem.

Code Improvements - Completed (P0, P1)

P0 - Bug Fixes

  • TestRunner auto-discovery: Fixed non-recursive test discovery in auto-discovery mode (ext/TestRunner.jl:614). Now uses _collect_test_files_recursive instead of flat readdir.

P1 - Typed Exceptions (Tenet 6)

Replaced all untyped error() and ArgumentError with structured CTBase exceptions:

P1a - src/Exceptions/types.jl

  • Fixed 2 occurrences of invalid Julia syntax catch e::CTBase.Exceptions.CTExceptioncatch e + e isa ... || rethrow()

P1b - ext/TestRunner.jl (7 replacements)

  • 3 × error() in _resolve_testCTBase.Exceptions.IncorrectArgument
  • 1 × error() in _run_single_test (function missing after include) → PreconditionError
  • 1 × error() in run_tests (subdirectory "test" forbidden) → PreconditionError
  • 2 × ArgumentError in _normalize_available_testsIncorrectArgument

P1c - ext/CoveragePostprocessing.jl (4 replacements)

  • 4 × error()PreconditionError

P1d - ext/DocumenterReference.jl (2 replacements)

  • public && private both false → IncorrectArgument
  • Invalid element in primary_modulesIncorrectArgument

P1e - ext/TestRunner.jl docstring

  • Fixed incorrect output in _progress_bar docstring (width=20 → 10 blocks, not 20)

P1f - Test updates

  • Updated 7 test files to reflect new exception types

Previous Code Improvements (from earlier commits)

  • Qualified imports: using DocStringExtensionsimport DocStringExtensions: TYPEDEF, TYPEDSIGNATURES (5 files)
  • Removed useless using Base: Base from CTBase.jl
  • Restructured test_exceptions.jl to follow module + callable pattern

Remaining Work (P2, P3)

P2 - Import Qualification & Code Cleanup

  • ext/TestRunner.jl: using DocStringExtensionsimport DocStringExtensions: TYPEDEF, TYPEDSIGNATURES
  • ext/CoveragePostprocessing.jl: using Coverageusing Coverage: Coverage
  • Remove dead ternary branches (ext/TestRunner.jl:447, 332)
  • Remove circular import using CTBase from src/Exceptions/Exceptions.jl
  • Remove redundant using DocStringExtensions from src/Descriptions/types.jl

P3 - Qualified Test Imports

  • Rewrite test imports to use import Test + import CTBase.Exceptions with qualified calls
  • Large mechanical change, deferred to separate phase

Testing

All tests pass: 1161/1161

Stack Position

CTBase is the foundational package in the stack:
CTBase → CTModels → CTFlows → CTSolvers → OptimalControl

ocots added 2 commits June 5, 2026 23:44
- Replace `using DocStringExtensions` with `import DocStringExtensions: TYPEDEF, TYPEDSIGNATURES` in all submodules (CTBase.jl, Core.jl, Descriptions.jl, Extensions.jl, Unicode.jl)
- Remove useless `using Base: Base` from CTBase.jl
- Restructure test_exceptions.jl to follow module + callable pattern with proper qualification
- Use `import CTBase.Exceptions` instead of `using CTBase` in tests
- Add VERBOSE/SHOWTIMING constants with fallback to defaults when TestOptions not available

These changes align the codebase with the philosophy defined in dev/philosophy/modules.md and dev/philosophy/testing-creation.md.
Macros like `@testset` must be imported with `using` not `import`.
Changed from `import Test` to `using Test` in test_exceptions.jl.
@ocots ocots added the run ci Trigger CI label Jun 5, 2026
ocots added 2 commits June 6, 2026 18:08
P0 - Bug Fixes:
- TestRunner auto-discovery: Fixed non-recursive test discovery (ext/TestRunner.jl:614)
  Now uses _collect_test_files_recursive instead of flat readdir

P1 - Typed Exceptions (Tenet 6):
Replaced all untyped error() and ArgumentError with structured CTBase exceptions

P1a - src/Exceptions/types.jl:
- Fixed 2 occurrences of invalid Julia syntax catch e::CTBase.Exceptions.CTException
  → catch e + e isa ... || rethrow()

P1b - ext/TestRunner.jl (7 replacements):
- 3 × error() in _resolve_test → CTBase.Exceptions.IncorrectArgument
- 1 × error() in _run_single_test (function missing after include) → PreconditionError
- 1 × error() in run_tests (subdirectory "test" forbidden) → PreconditionError
- 2 × ArgumentError in _normalize_available_tests → IncorrectArgument

P1c - ext/CoveragePostprocessing.jl (4 replacements):
- 4 × error() → PreconditionError

P1d - ext/DocumenterReference.jl (2 replacements):
- public && private both false → IncorrectArgument
- Invalid element in primary_modules → IncorrectArgument

P1e - ext/TestRunner.jl docstring:
- Fixed incorrect output in _progress_bar docstring (width=20 → 10 blocks, not 20)

P1f - Test updates:
- Updated 7 test files to reflect new exception types

Code cleanup:
- Removed circular import using CTBase from src/Exceptions/Exceptions.jl
- Removed redundant using DocStringExtensions from src/Descriptions/types.jl

All tests pass: 1161/1161
@ocots

ocots commented Jun 6, 2026

Copy link
Copy Markdown
Member Author

Updated Summary (P2 completed)

This PR adds philosophy documentation and applies code standards to align with the control-toolbox ecosystem conventions.

Documentation Added

  • AGENTS.md: Agent navigation guide for CTBase.jl
  • CLAUDE.md: Claude project context with essential rules
  • dev/philosophy/: Code philosophy documentation
    • modules.md: Submodule organization, imports/qualification, DAG, exports
    • types-traits-interfaces.md: Types vs traits, interfaces/contracts, SOLID/DRY/YAGNI, type stability
    • exceptions.md: The 7 exceptions and the choice rule
    • docstrings.md: Docstring templates, cross-references, example safety
    • testing.md: Categories, fakes/stubs, module + callable function template
    • documentation.md: API generation, guides, draft workflow
  • dev/planning.md: Implementation plan template
  • dev/RULES.md: Operational rules (MCP, doc build, git, output capture)

Code Improvements - Completed (P0, P1, P2)

P0 - Bug Fixes

  • TestRunner auto-discovery: Fixed non-recursive test discovery in auto-discovery mode (ext/TestRunner.jl:614). Now uses _collect_test_files_recursive instead of flat readdir.

P1 - Typed Exceptions (Tenet 6)

Replaced all untyped error() and ArgumentError with structured CTBase exceptions:

P1a - src/Exceptions/types.jl

  • Fixed 2 occurrences of invalid Julia syntax catch e::CTBase.Exceptions.CTExceptioncatch e + e isa ... || rethrow()

P1b - ext/TestRunner.jl (7 replacements)

  • 3 × error() in _resolve_testCTBase.Exceptions.IncorrectArgument
  • 1 × error() in _run_single_test (function missing after include) → PreconditionError
  • 1 × error() in run_tests (subdirectory "test" forbidden) → PreconditionError
  • 2 × ArgumentError in _normalize_available_testsIncorrectArgument

P1c - ext/CoveragePostprocessing.jl (4 replacements)

  • 4 × error()PreconditionError

P1d - ext/DocumenterReference.jl (2 replacements)

  • public && private both false → IncorrectArgument
  • Invalid element in primary_modulesIncorrectArgument

P1e - ext/TestRunner.jl docstring

  • Fixed incorrect output in _progress_bar docstring (width=20 → 10 blocks, not 20)

P1f - Test updates

  • Updated 7 test files to reflect new exception types

P2 - Import Qualification & Code Cleanup

  • ext/TestRunner.jl: using DocStringExtensionsimport DocStringExtensions: TYPEDEF, TYPEDSIGNATURES
  • ext/CoveragePostprocessing.jl: using Coverageusing Coverage: Coverage
  • Removed dead ternary branches (ext/TestRunner.jl:447, 332)
  • Removed circular import using CTBase from src/Exceptions/Exceptions.jl
  • Removed redundant using DocStringExtensions from src/Descriptions/types.jl
  • Fixed byte-indexing path slicing → use relpath() (ext/CoveragePostprocessing.jl:347)
  • Fixed collision risk in cov file flattening → use normalized flat names (ext/CoveragePostprocessing.jl:221)

Previous Code Improvements (from earlier commits)

  • Qualified imports: using DocStringExtensionsimport DocStringExtensions: TYPEDEF, TYPEDSIGNATURES (5 files in src/)
  • Removed useless using Base: Base from CTBase.jl
  • Restructured test_exceptions.jl to follow module + callable pattern

Remaining Work (P3)

P3 - Qualified Test Imports

  • Rewrite test imports to use import Test + import CTBase.Exceptions with qualified calls
  • Large mechanical change, deferred to separate phase

Testing

All tests pass: 1161/1161

Stack Position

CTBase is the foundational package in the stack:
CTBase → CTModels → CTFlows → CTSolvers → OptimalControl

P2 - Import Qualification & Code Cleanup:
- ext/TestRunner.jl: using DocStringExtensions → import DocStringExtensions: TYPEDEF, TYPEDSIGNATURES
- ext/CoveragePostprocessing.jl: using Coverage → using Coverage: Coverage
- Removed dead ternary branches (ext/TestRunner.jl:447, 332)
- Fixed byte-indexing path slicing → use relpath() (ext/CoveragePostprocessing.jl:347)
- Fixed collision risk in cov file flattening → use normalized flat names (ext/CoveragePostprocessing.jl:221)

All tests pass: 1161/1161
@ocots

ocots commented Jun 6, 2026

Copy link
Copy Markdown
Member Author

Additional Changes - Documentation Improvements

docs/make.jl

  • Changed documentation build method from Pkg.activate/instantiate to pushfirst!(LOAD_PATH, ...) for faster builds and better control over load order

src/Exceptions/types.jl - Docstring Refactoring

Rewrote docstrings for better consistency with philosophy standards:

ExtensionError

  • Added $(TYPEDEF) macro
  • Simplified description to focus on weak dependencies
  • Moved constructor throws to # Throws section
  • Consolidated examples into single # Example section
  • Added cross-reference to PreconditionError
  • Removed redundant "Common Use Cases" section

SolverFailure

  • Added $(TYPEDEF) macro
  • Clarified distinction from IncorrectArgument and PreconditionError
  • Added cross-references to related exception types
  • Simplified examples and removed redundant sections

src/Extensions/Extensions.jl - Cross-Reference Fixes

  • Added example code blocks for CoveragePostprocessingTag, AbstractTestRunnerTag, and TestRunnerTag
  • Fixed cross-references from CTBase.* to CTBase.Extensions.* for:
    • AbstractCoveragePostprocessingTag
    • TestRunnerTag
    • AbstractTestRunnerTag

These changes resolve Documenter warnings about unresolved @ref links during documentation builds.

Testing

All tests pass: 1161/1161

Documentation builds successfully with no extension errors.

ocots added 2 commits June 6, 2026 20:50
…ences

docs/make.jl:
- Changed from Pkg.activate/instantiate to pushfirst!(LOAD_PATH, ...) for faster builds

src/Exceptions/types.jl:
- Added $(TYPEDEF) macro to ExtensionError and SolverFailure
- Simplified docstrings to focus on core functionality
- Moved constructor throws to # Throws section
- Consolidated examples and removed redundant sections
- Added cross-references to related exception types

src/Extensions/Extensions.jl:
- Added example code blocks for CoveragePostprocessingTag, AbstractTestRunnerTag, TestRunnerTag
- Fixed cross-references from CTBase.* to CTBase.Extensions.*

docs/:
- Updated guide files and index
- Added getting-started.md
- Updated Project.toml and README.md

All tests pass: 1161/1161
Documentation builds successfully
- Bumped version to 0.18.15-beta in Project.toml
- Added comprehensive changelog entry for 0.18.15-beta covering:
  - Philosophy documentation additions
  - Documentation build improvements
  - Bug fixes (TestRunner auto-discovery, typed exceptions)
  - Code quality improvements (import qualification, cleanup)
- Added non-breaking note to BREAKINGS.md for 0.18.15-beta
- All changes are internal or documentation-only; no breaking changes
@ocots ocots added run documentation Trigger documentation and removed run ci Trigger CI labels Jun 6, 2026
Added `types: [labeled, synchronize, opened, reopened]` to pull_request triggers in CI.yml and Documentation.yml for better control over when workflows run on PRs.
@ocots
ocots merged commit 5325c5a into main Jun 6, 2026
4 checks passed
@ocots
ocots deleted the philosophy-docs-and-code-fixes branch June 6, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run documentation Trigger documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant