<commit_before>// Provides tasks to spawn and kill subprocesses needed for todos app.
// See also: javascript/api/grunt_tasks/integration_test_environment_setup.js

var assert = require('assert');
var fs = require('fs');
var spawn = require('child_process').spawn;

module.exports = function(grunt) {
  var subprocesses = [];  // List of subprocesses we've spawned.

  // Kills all subprocesses we've spawned.
  var tearDown = function() {
    subprocesses.forEach(function(p) {
      p.kill('SIGTERM');
    });
  };

  // Calls tearDown, then fails the current task.
  var fail = function(msg) {
    tearDown();
    grunt.fail.fatal(msg);
    done(false);
  };

  // Starts all subprocesses and sets some grunt.config vars.
  grunt.registerTask('subtask_spawnSubprocesses', function() {
    // Tell grunt that this is an async task.
    // Note, we never actually call done() -- see comment below.
    var done = this.async();

    // Define constants.
    var c = grunt.constants;
    var VEYRON_IDENTITY_BIN = c.VEYRON_BIN_DIR + '/identityd';
    var VEYRON_PROXY_BIN = c.VEYRON_BIN_DIR + '/proxyd';
    var VEYRON_WSPR_BIN = c.VEYRON_BIN_DIR + '/wsprd';
    var STORE_BIN = c.VEYRON_BIN_DIR + '/todos_stored';
    var VEYRON_PROXY_ADDR = '127.0.0.1:' + c.VEYRON_PROXY_PORT;

    // Ensure binaries exist.
    var bins = [VEYRON_IDENTITY_BIN, VEYRON_PROXY_BIN, VEYRON_WSPR_BIN];
    bins.forEach(function(bin) {
      if (!fs.existsSync(bin)) {
        fail('Missing binary: ' + bin);
      }
    });

    // Start subprocesses.
    var startSubprocess = function(command, args) {
      var p = spawn(command, args);
      p.stderr.on('data', grunt.log.debug);
      subprocesses.push(p);
      return p;
    };
    var veyronIdentitySubprocess = startSubprocess(
        VEYRON_IDENTITY_BIN,
        ['-port=' + c.VEYRON_IDENTITY_PORT]);
    var veyronProxySubprocess = startSubprocess(
        VEYRON_PROXY_BIN,
        ['-log_dir=' + c.LOG_DIR, '-addr=' + VEYRON_PROXY_ADDR]);
    var veyronWsprSubprocess = startSubprocess(
        VEYRON_WSPR_BIN,
        ['-v=3', '-log_dir=' + c.LOG_DIR, '-port=' + c.VEYRON_WSPR_PORT,
         '-vproxy=' + VEYRON_PROXY_ADDR]);
    var storeSubprocess = startSubprocess(
        STORE_BIN, ['-log_dir=' + c.LOG_DIR]);

    // Capture todos_stored's endpoint, then write env.js file.
    storeSubprocess.stdout.on('data', function(data) {
      var endpoint;
      data.toString().split('\n').some(function(line) {
        line = line.replace('Endpoint: ', '').trim();<commit_msg>javascript: Run identityd with --httpaddr instead of --address<commit_after>// Provides tasks to spawn and kill subprocesses needed for todos app.
// See also: javascript/api/grunt_tasks/integration_test_environment_setup.js

var assert = require('assert');
var fs = require('fs');
var spawn = require('child_process').spawn;

module.exports = function(grunt) {
  var subprocesses = [];  // List of subprocesses we've spawned.

  // Kills all subprocesses we've spawned.
  var tearDown = function() {
    subprocesses.forEach(function(p) {
      p.kill('SIGTERM');
    });
  };

  // Calls tearDown, then fails the current task.
  var fail = function(msg) {
    tearDown();
    grunt.fail.fatal(msg);
    done(false);
  };

  // Starts all subprocesses and sets some grunt.config vars.
  grunt.registerTask('subtask_spawnSubprocesses', function() {
    // Tell grunt that this is an async task.
    // Note, we never actually call done() -- see comment below.
    var done = this.async();

    // Define constants.
    var c = grunt.constants;
    var VEYRON_IDENTITY_BIN = c.VEYRON_BIN_DIR + '/identityd';
    var VEYRON_PROXY_BIN = c.VEYRON_BIN_DIR + '/proxyd';
    var VEYRON_WSPR_BIN = c.VEYRON_BIN_DIR + '/wsprd';
    var STORE_BIN = c.VEYRON_BIN_DIR + '/todos_stored';
    var VEYRON_PROXY_ADDR = '127.0.0.1:' + c.VEYRON_PROXY_PORT;

    // Ensure binaries exist.
    var bins = [VEYRON_IDENTITY_BIN, VEYRON_PROXY_BIN, VEYRON_WSPR_BIN];
    bins.forEach(function(bin) {
      if (!fs.existsSync(bin)) {
        fail('Missing binary: ' + bin);
      }
    });

    // Start subprocesses.
    var startSubprocess = function(command, args) {
      var p = spawn(command, args);
      p.stderr.on('data', grunt.log.debug);
      subprocesses.push(p);
      return p;
    };
    var veyronIdentitySubprocess = startSubprocess(
        VEYRON_IDENTITY_BIN,
        ['-httpaddr=localhost:' + c.VEYRON_IDENTITY_PORT]);
    var veyronProxySubprocess = startSubprocess(
        VEYRON_PROXY_BIN,
        ['-log_dir=' + c.LOG_DIR, '-addr=' + VEYRON_PROXY_ADDR]);
    var veyronWsprSubprocess = startSubprocess(
        VEYRON_WSPR_BIN,
        ['-v=3', '-log_dir=' + c.LOG_DIR, '-port=' + c.VEYRON_WSPR_PORT,
         '-vproxy=' + VEYRON_PROXY_ADDR]);
    var storeSubprocess = startSubprocess(
        STORE_BIN, ['-log_dir=' + c.LOG_DIR]);

    // Capture todos_stored's endpoint, then write env.js file.
    storeSubprocess.stdout.on('data', function(data) {
      var endpoint;
      data.toString().split('\n').some(function(line) {
        line = line.replace('Endpoint: ', '').trim();
{'fraction_non_alphanumeric': 0.13583871599138775, 'fraction_numerical': 0.002740262282247015, 'mean_word_length': 3.094551282051282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '357870', 'n_tokens_mistral': 1836, 'n_tokens_neox': 1767, 'n_words': 378}