Skip to content

CFE-3105: Made format collect data container - #6223

Open
victormlg wants to merge 2 commits into
cfengine:masterfrom
victormlg:make_format_collecting
Open

CFE-3105: Made format collect data container#6223
victormlg wants to merge 2 commits into
cfengine:masterfrom
victormlg:make_format_collecting

Conversation

@victormlg

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread libpromises/evalfunction.c Fixed
Comment thread libpromises/evalfunction.c Fixed
@victormlg
victormlg force-pushed the make_format_collecting branch from bf0432b to 9667796 Compare July 9, 2026 10:31
Comment thread libpromises/evalfunction.c Fixed
@victormlg
victormlg force-pushed the make_format_collecting branch 8 times, most recently from 3a40ef1 to 10d94b8 Compare July 10, 2026 13:35
@victormlg
victormlg force-pushed the make_format_collecting branch 2 times, most recently from 4374730 to 34a6da4 Compare August 4, 2026 09:25
@victormlg
victormlg marked this pull request as ready for review August 4, 2026 09:25
@victormlg
victormlg requested a review from larsewi August 4, 2026 10:36

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you perhaps use VarNameOrInlineToJson() to achieve this?

@victormlg

victormlg commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Could you perhaps use VarNameOrInlineToJson() to achieve this?

That was my initial idea, however this would break backwards compatibility because string lists are formatted differently from data containers and VarNameOrInlineToJson() parses string lists as data containers.

bundle agent main
{
  vars:
    "stringlist" slist => { "a", "b" };
    "array" data => parsejson('["a", "b"]');
    "str1" string => format("%S", array);
    "str2" string => format("%S", stringlist);

  reports:
    "$(str1)";
    "$(str2)";
}
R: ["a","b"]
R: { "a", "b" } # special case, with current implementation

Comment thread tests/acceptance/01_vars/02_functions/format.cf
Comment thread tests/acceptance/01_vars/02_functions/format.cf Outdated
@victormlg
victormlg force-pushed the make_format_collecting branch 3 times, most recently from 27c9517 to b7dc4ac Compare August 10, 2026 09:20
JsonWriteCompact(w, element);
BufferAppendF(buf, format_rewrite, StringWriterData(w));
WriterClose(w);
JsonDestroyMaybe(element, allocated);
Comment thread libpromises/evalfunction.c Outdated
Ticket: CFE-3105
Changelog: Title
Signed-off-by: Victor Moene <victor.moene@northern.tech>
From the docs:

"The list which getindices returns is not guaranteed to be in any specific order."

The tests failed for me but it didnt' seem related to format()

Signed-off-by: Victor Moene <victor.moene@northern.tech>
@victormlg
victormlg force-pushed the make_format_collecting branch from b7dc4ac to ee666b2 Compare August 10, 2026 14:43
@victormlg

Copy link
Copy Markdown
Contributor Author

Got this error, thus the second commit:

R: FILES DIFFER BUT SHOULD BE THE SAME
R: CONTENTS OF /home/runner/work/core/core/tests/acceptance/workdir/__01_vars_02_functions_nth_datacontainer_cf/tmp/TEST.cfengine.actual:
jsonstring = {"boolean":true,"boolean_2":false,"integer":20130111,"integer_2":987654321,"list":["chris","dituri","was","here"],"null":null,"object":{"a":true,"b":[1,2,3],"c":"cat","d":108},"string":"Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!","string_2":"Othello? Where art thou now?"}
keys:json = boolean
keys:json = string
keys:json = integer
keys:json = list
keys:json = object
keys:json = integer_2
keys:json = string_2
keys:json = boolean_2
keys:json = null
primitive:json[boolean] = true
primitive:json[string] = Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!
primitive:json[integer] = 20130111
primitive:json[integer_2] = 987654321
primitive:json[string_2] = Othello? Where art thou now?
primitive:json[boolean_2] = false
primitive:json[null] = null
list:json[0] = chris
list:json[1] = dituri
list:json[2] = was
list:json[3] = here
object:json[a] = true
object:json[c] = cat
object:json[d] = 108

R: CONTENTS OF /home/runner/work/core/core/tests/acceptance/workdir/__01_vars_02_functions_nth_datacontainer_cf/tmp/TEST.cfengine.expected:
jsonstring = {"boolean":true,"boolean_2":false,"integer":20130111,"integer_2":987654321,"list":["chris","dituri","was","here"],"null":null,"object":{"a":true,"b":[1,2,3],"c":"cat","d":108},"string":"Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!","string_2":"Othello? Where art thou now?"}
keys:json = boolean
keys:json = boolean_2
keys:json = integer
keys:json = integer_2
keys:json = list
keys:json = null
keys:json = object
keys:json = string
keys:json = string_2
primitive:json[boolean] = true
primitive:json[boolean_2] = false
primitive:json[integer] = 20130111
primitive:json[integer_2] = 987654321
primitive:json[null] = null
primitive:json[string] = Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!
primitive:json[string_2] = Othello? Where art thou now?
list:json[0] = chris
list:json[1] = dituri
list:json[2] = was
list:json[3] = here
object:json[a] = true
object:json[c] = cat
object:json[d] = 108

R: --- /home/runner/work/core/core/tests/acceptance/workdir/__01_vars_02_functions_nth_datacontainer_cf/tmp/TEST.cfengine.expected	2026-08-10 09:41:09.771766724 +0000
+++ /home/runner/work/core/core/tests/acceptance/workdir/__01_vars_02_functions_nth_datacontainer_cf/tmp/TEST.cfengine.actual	2026-08-10 09:41:09.779927634 +0000
@@ -1,20 +1,20 @@
 jsonstring = {"boolean":true,"boolean_2":false,"integer":20130111,"integer_2":987654321,"list":["chris","dituri","was","here"],"null":null,"object":{"a":true,"b":[1,2,3],"c":"cat","d":108},"string":"Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!","string_2":"Othello? Where art thou now?"}
 keys:json = boolean
-keys:json = boolean_2
+keys:json = string
 keys:json = integer
-keys:json = integer_2
 keys:json = list
-keys:json = null
 keys:json = object
-keys:json = string
+keys:json = integer_2
 keys:json = string_2
+keys:json = boolean_2
+keys:json = null
 primitive:json[boolean] = true
-primitive:json[boolean_2] = false
+primitive:json[string] = Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!
 primitive:json[integer] = 20130111
 primitive:json[integer_2] = 987654321
-primitive:json[null] = null
-primitive:json[string] = Figaro. Figaro. Figaro, Figaro, Figaro... Figaro!
 primitive:json[string_2] = Othello? Where art thou now?
+primitive:json[boolean_2] = false
+primitive:json[null] = null
 list:json[0] = chris
 list:json[1] = dituri
 list:json[2] = was
R: /home/runner/work/core/core/tests/acceptance/./01_vars/02_functions/nth_datacontainer.cf FAIL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants