Skip to content

Conversation

@jsoriano
Copy link
Member

@jsoriano jsoriano commented Nov 19, 2025

Swap source and build package roots when updating READMEs, so the generator looks for fields in the source directory. In the build directory the external fields have been already resolved and they don't include the external key.

For legacy reasons, elastic-package only renders groups in READMEs when they are external, so these fields were not being rendered.

See

if (len(f.Fields) == 0 && f.Type != "group") || f.External != "" {

Naming of related variables is reviewed for consistency, so it is harder to misuse them.

Fix also related tests, and introduce new ones that reproduce the issue.

@jsoriano jsoriano requested a review from a team November 19, 2025 20:47
@jsoriano jsoriano self-assigned this Nov 19, 2025
@jsoriano jsoriano enabled auto-merge (squash) November 19, 2025 20:54
@jsoriano
Copy link
Member Author

test integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#16027

@jsoriano
Copy link
Member Author

This change produces new issues, moving to draft by now.

@jsoriano jsoriano marked this pull request as draft November 19, 2025 21:50
auto-merge was automatically disabled November 19, 2025 21:50

Pull request was converted to draft

Documentations rendering was looking for fields in the built directory,
there the external fields have been already resolved and they don't
include the external key.

For legacy reasons, elastic-package only renders groups in READMEs when
they are external, so these fields were not being rendered.
@jsoriano jsoriano force-pushed the fix-rendering-external-groups branch from 01b0fa1 to 8bee428 Compare November 19, 2025 22:07
@jsoriano
Copy link
Member Author

test integrations

@jsoriano jsoriano marked this pull request as ready for review November 19, 2025 22:14
@jsoriano
Copy link
Member Author

Ok, last commit seemed to work, going on with the PR.

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#16027

}
}

func TesRenderReadmeWithFields(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

These tests were not being executed because the function doesn't start with Test 🙁 After fixing the name, the tests weren't working.

Comment on lines +273 to +274
finder := packageRoot{from: fieldsParentDir}
return createValidatorForDirectoryAndPackageRoot(fieldsParentDir, finder, opts...)
Copy link
Member Author

Choose a reason for hiding this comment

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

These changes are needed for tests, but I guess it is fine to look for the package root from the fields directory instead of from the current directory?

Copy link
Contributor

Choose a reason for hiding this comment

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

the finder is needed to validate the condition from https://github.com/elastic/elastic-package/pull/3088/files#diff-36d325d58b4ea8957abc63576d2e04d30ec8e58435ba06d442cb7923af063ad3L291 and throw an error if dependency management is enabled and there is no package root...

I suggest to inject the function as a param func(string) (string,error) and use the implementation packages.FindPackageRootFrom for the code and use mocks for the tests. we could inject a mock and assert if the finder is called or not

i also thought of getting the packageRoot and pass it through the function as a string param, but this operation is only executed when there is dependency management.

Copy link
Member Author

Choose a reason for hiding this comment

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

the finder is needed to validate the condition from https://github.com/elastic/elastic-package/pull/3088/files#diff-36d325d58b4ea8957abc63576d2e04d30ec8e58435ba06d442cb7923af063ad3L291 and throw an error if dependency management is enabled and there is no package root...

Yes, this is working now. This is why I needed to update createManifestFile in tests to generate a more valid manifest.

I suggest to inject the function as a param func(string) (string,error) and use the implementation packages.FindPackageRootFrom for the code and use mocks for the tests. we could inject a mock and assert if the finder is called or not

Something like this is done in the tests for this function, passing the "finder" to createValidatorForDirectoryAndPackageRoot. I would not change the public CreateValidatorForDirectory unless this is introducing some issue, at least on this PR.

i also thought of getting the packageRoot and pass it through the function as a string param, but this operation is only executed when there is dependency management.

Dependency management is used basically always in real use cases 🙂

We can definitely apply more refactors around paths, but not sure if more refactors are needed here. I think we should review the location manager, place there all the logic we have to find paths and define interfaces that other components can use.

docsFolder, err := createDocsFolder(packageRoot)
if err != nil {
return err
func TestUpdateReadmeWithFields(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This test reproduces the issue that this PR fixes.

// the readme template reads data from the sourceFilesRoot directory.
// sourceFilesRoot is usually the package root when generating readme for checking up-to-dateness,
// and the built package root when generating readme for the built package.
func generateReadme(fileName, linksFilePath, packageRoot, sourceFilesRoot string) ([]byte, bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func generateReadme(fileName, linksFilePath, packageRoot, sourceFilesRoot string) ([]byte, bool, error) {
func generateReadme(fileName, linksFilePath, sourceFilesRoot string) ([]byte, bool, error) {

packageRoot and sourceFilesRoot is the same / should be the same value from the source of the package. I was confused when this function is called at updateReadme I was passing along the build source instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, packageRoot is not used now, removing it in 085b41e.

Copy link
Contributor

Choose a reason for hiding this comment

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

overall, i think we should come up with a "convention" on how to call things:

  • sourceFilesRoot == packageRoot
  • the "buildFolderRoot"

i think i messed up trying to call things by their name.

Also, for the renderExportedFields(fieldsParentDir string) that is a data stream root path? but i see some examples where this is not a data stream path

"fields": func(args ...string) (string, error) {
			if len(args) > 0 {
				dataStreamPath := filepath.Join(sourceFilesRoot, "data_stream", args[0])
				return renderExportedFields(dataStreamPath)
			}
			return renderExportedFields(sourceFilesRoot)
		},

Copy link
Member Author

Choose a reason for hiding this comment

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

Using more consistent names in 3b1f9c9.

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @jsoriano

@jsoriano jsoriano requested a review from a team November 20, 2025 11:38
Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

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

👍

@jsoriano jsoriano merged commit 83e649d into elastic:main Nov 20, 2025
3 checks passed
@jsoriano jsoriano deleted the fix-rendering-external-groups branch November 20, 2025 15:04
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.

4 participants