Repository: promptfoo/promptfoo
Issue: TransformVars doesn't support vars in defaultTest
Root cause: Algorithmic Error

**Describe the bug**
We can't use the `transformVars` property on `vars` present in `defaultTest`

**To Reproduce**
Here a dummy example to reproduce : 
``` yaml
description: My eval
prompts:
  - id: "my_prompt"
    raw: "what is the color of the sky ?"
providers:
  - openai:gpt-4o

defaultTest:
  vars:
    test2: bar
  options:
    transformVars: |
      console.log(vars)
      return {
        test2UpperCase: vars.test2.toUpperCase()
      };
  assert:
    - type: javascript
      value: true == true

tests:
  - vars:
      test1: foo

writeLatestResults: true
sharing: true
```

**Expected behavior**
We should have a new variable named `test2UpperCase` with `BAR` in uppercase. But we have this error instead :
```
{ test1: 'foo' }
undefined:6
  test2UpperCase: vars.test2.toUpperCase()
                             ^

TypeError: Cannot read properties of undefined (reading 'toUpperCase')
    at eval (eval at getInlineTransformFunction (/home/maxime/.nvm/versions/node/v20.17.0/lib/node_modules/promptfoo/dist/src/util/transform.js:81:12), <anonymous>:6:30)
    at transform (/home/maxime/.nvm/versions/node/v20.17.0/lib/node_modules/promptfoo/dist/src/util/transform.js:111:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Evaluator.evaluate (/home/maxime/.nvm/versions/node/v20.17.0/lib/node_modules/promptfoo/dist/src/evaluator.js:466:45)
    at async runEvaluation (/home/maxime/.nvm/versions/node/v20.17.0/lib/node_modules/promptfoo/dist/src/commands/eval.js:189:9)
    at async doEval (/home/maxime/.nvm/versions/node/v20.17.0/lib/node_modules/promptfoo/dist/src/commands/eval.js:352:5)

Node.js v20.17.0
```

Please note the console.log with only the `test1` var.

**System information:**
```
==================================================================================================================================================
Promptfoo Debug Information
==================================================================================================================================================
{
  "version": "0.99.0",
  "platform": {
    "os": "linux",
    "release": "5.15.146.1-microsoft-standard-WSL2",
    "arch": "x64",
    "nodeVersion": "v20.17.0"
  },
  "env": {},
  "configInfo": {
    "defaultConfigPath": "/home/maxime/workspace/diag-auto/promptfoo2/promptfooconfig.yaml",
    "configExists": true,
    "configContent": {
      "config": {
        "tags": {},
        "description": "My eval",
        "prompts": [
          {
            "id": "my_prompt",
            "raw": "what is the color of the sky ?"
          }
        ],
        "providers": [
          "openai:gpt-4o"
        ],
        "tests": [
          {
            "vars": {
              "test1": "foo"
            }
          }
        ],
        "scenarios": [],
        "env": {},
        "sharing": true,
        "defaultTest": {
          "vars": {
            "test2": "bar"
          },
          "options": {
            "transformVars": "console.log(vars)\nreturn {\n  test2UpperCase: vars.test2.toUpperCase()\n};\n"
          },
          "assert": [
            {
              "type": "javascript",
              "value": "true == true"
            }
          ],
          "metadata": {}
        },
        "outputPath": [],
        "extensions": [],
        "metadata": {}
      },
      "testSuite": {
        "description": "My eval",
        "tags": {},
        "prompts": [
          {
            "raw": "what is the color of the sky ?",
            "label": "what is the color of the sky ?"
          }
        ],
        "providers": [
          {
            "env": {},
            "modelName": "gpt-4o",
            "config": {
              "basePath": "/home/maxime/workspace/diag-auto/promptfoo2"
            },
            "label": ""
          }
        ],
        "providerPromptMap": {},
        "tests": [
          {
            "vars": {
              "test1": "foo"
            }
          }
        ],
        "scenarios": [],
        "defaultTest": {
          "metadata": {},
          "options": {
            "transformVars": "console.log(vars)\nreturn {\n  test2UpperCase: vars.test2.toUpperCase()\n};\n"
          },
          "vars": {
            "test2": "bar"
          },
          "assert": [
            {
              "type": "javascript",
              "value": "true == true"
            }
          ]
        },
        "nunjucksFilters": {},
        "extensions": []
      },
      "basePath": "/home/maxime/workspace/diag-auto/promptfoo2"
    }
  }
}
==================================================================================================================================================
```

- Promptfoo version: 0.99.0

Hey @maximepichou double check your config. `vars.test2.toUpperCase()` should be `vars.test1.toUpperCase()`. `test2` is not defined until after the code is executed. Mistakes like this are easy to make - it took me a while to notice it. Please let us know if you run into any other issues! 

Hello @mldangelo,
Thank you for your response, but I'm not sure I fully understand.
If I declare `test2` in the `vars` of `defaultTest`, does that mean I can't use it in `transformVars`? Why are only variables defined in `tests` available in `transformVars`?

Same question as @maximepichou. Are the `vars` from `defaultTest` injected after `transformVars` has been run?

Thank you @maximepichou and @sbichenko for following up on this issue! You both raised a valid point - defaultTest.vars should definitely be available during transformVars execution.

I've just opened #2339 that fixes this behavior. Your example config should work as expected after this change. Thanks for helping us identify and clarify this issue! Let me know if you run into any other questions.