Skip to content

Provide path_to_schema to schema definition state - #1316

Open
jwils wants to merge 1 commit into
mainfrom
joshuaw/artifact-manager-schema-path
Open

Provide path_to_schema to schema definition state#1316
jwils wants to merge 1 commit into
mainfrom
joshuaw/artifact-manager-schema-path

Conversation

@jwils

@jwils jwils commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Today, every schema artifact is a pure function of the schema definition: the schema artifacts directory can safely be deleted and regenerated at any time. In #1304 (comment), @myronmarston pointed out that proto_field_numbers.yaml doesn't fit that model--it's an input to schema.proto generation, not a pure output--and suggested treating it as part of the schema definition, stored as a sibling of path_to_schema, rather than as a schema artifact.

For an extension to maintain a file there, schema definition state needs to know where the schema definition lives. RakeTasks already knows (it's how the schema gets loaded) but never passed it into the API. This PR stores path_to_schema on SchemaDefinition::State, allowing extensions to access it without expanding SchemaArtifactManager's dependencies.

Nothing in core uses the value yet, so there are no behavior changes to the core artifacts. #1304 builds on this to relocate proto_field_numbers.yaml.

Update — 2026-07-29

After review, the path is carried by schema definition state rather than an extension-only SchemaArtifactManager instance variable. The manager continues to accept the narrower schema-definition results object.

@schema_artifacts_directory = schema_artifacts_directory
# Supports extensions that need to maintain files alongside the schema definition, rather
# than in the schema artifacts directory.
@path_to_schema = path_to_schema

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems weird to store it on SchemaArtifactManager when it's not used by SchemaArtifactManager. And instance variables are in general a more brittle extension mechanism because if of how Ruby treats ivars: they spring into existence when first referenced, so if you mispell the name of the ivar, Ruby will just make a new one.

An alternate suggestion:

  • Store path_to_schema on SchemaDefinitition::State
  • Change SchemaArtifactManager to accept schema_def_api (which has access to state) rather than schema_definition_results--it can call schema_def_api.results to get the results, and that way an extension has access to schema_def_api.state.path_to_schema.

Separately, it's worth considering if it's best to have SchemaArtifactManager generate the proto numbers file. If we're saying it's not a schema artifact, it seems odd to have the SchemaArtifactManager dump it!

That said:

  • Apart from the slight naming mismatch, I don't see a reason to not have SchemaArtifactManager dump it.
  • I'd only consider having it generated somewhere else if it was just as simple. If it's much more complex to dump it from somewhere else then I'd rather do it in a SchemaArtifactManager extension in spite of the name mis-match.
  • One concrete thing the SchemaArtifactManager does is checks all the artifacts (when you run be rake schema_artifacts:check). It's not clear to me if that's meaningful and useful for the proto numbers file or not. (I'm guessing it is, becaues that's probably how you'd ensure every field and enum value is in the file.)

Thoughts?

Schema definition extensions may need to maintain inputs alongside the schema file. Carry the configured path on State so extensions can access it without expanding SchemaArtifactManager dependencies.
@jwils
jwils force-pushed the joshuaw/artifact-manager-schema-path branch from 20d16fd to 41f7655 Compare July 29, 2026 19:13

@myronmarston myronmarston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM apart from a suggestion below and one other thing: the PR description is no longer accurate. Worth updating before you merge?

@api = SchemaDefinition::API.new(
SchemaArtifacts::RuntimeMetadata::SchemaElementNames.new(form: :camelCase, overrides: {}),
true,
path_to_schema: "#{@tmp_dir}/schema.rb",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does "#{@tmp_dir}/schema.rb" even exist? I'd prefer not to lie and claim it does if it doesn't exist. And it looks like the path_to_schema: arg is optional...should we just omit it here or do we need it for some reason I'm not thinking of?

@jwils jwils changed the title Provide path_to_schema to SchemaArtifactManager Provide to schema definition state Jul 29, 2026
@jwils jwils changed the title Provide to schema definition state Provide path_to_schema to schema definition state Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants